Questions tagged [hex]

Hexadecimal (also base 16, or hex) is the base-16 positional numeral system, using the 16 symbols 0–9 and A‒F.

Hexadecimal (also base 16, or hex) is a numeral system with a base of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F (or alternatively a–f) to represent values ten to fifteen.

Each hexadecimal digit represents four binary digits (bits), and the primary use of hexadecimal notation is a human-friendly representation of binary-coded values in computing and digital electronics. More information may be found here.

Other numeral systems:

9640 questions
82
votes
7 answers

Conversion hex string into ascii in bash command line

I have a lot of this kind of string and I want to find a command to convert it in ascii, I tried with echo -e and od, but it did not work. 0xA7.0x9B.0x46.0x8D.0x1E.0x52.0xA7.0x9B.0x7B.0x31.0xD2
Kerby82
  • 4,934
  • 14
  • 48
  • 74
79
votes
16 answers

Convert integer to hex and hex to integer

So I have this query working (where signal_data is a column) in Sybase but it doesn't work in Microsoft SQL Server: HEXTOINT(SUBSTRING((INTTOHEX(signal_data)),5,2)) as Signal I also have it in Excel (where A1 contains the…
Nick Sinas
  • 2,594
  • 11
  • 42
  • 51
79
votes
4 answers

How to convert Int to Hex string in Kotlin?

I'm looking for a similar function to Java's Integer.toHexString() in Kotlin. Is there something built-in, or we have to manually write a function to convert Int to String?
milosmns
  • 3,595
  • 4
  • 36
  • 48
78
votes
10 answers

Python 3 string to hex

In Python 2 these all worked: >>> "hello".encode("hex") '68656c6c6f' >>> b"hello".encode("hex") '68656c6c6f' >>> u"hello".encode("hex") '68656c6c6f' But in Python 3: >>> "hello".encode("hex") LookupError: 'hex' is not a text encoding; use…
Stuart
  • 1,733
  • 4
  • 21
  • 34
77
votes
14 answers

C++ convert string to hexadecimal and vice versa

What is the best way to convert a string to hex and vice versa in C++? Example: A string like "Hello World" to hex format: 48656C6C6F20576F726C64 And from hex 48656C6C6F20576F726C64 to string: "Hello World"
Sebtm
  • 7,002
  • 8
  • 29
  • 32
77
votes
6 answers

How can I get a hex dump of a string in PHP?

I'm investigating encodings in PHP5. Is there some way to get a raw hex dump of a string? i.e. a hex representation of each of the bytes (not characters) in a string?
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
75
votes
8 answers

How to get the background color code of an element in hex?

How do I get the background color code of an element? console.log($(".div").css("background-color"));
Run
  • 54,938
  • 169
  • 450
  • 748
75
votes
5 answers

Show u8 slice in hex representation

I need to convert &[u8] to a hex representation. For example [ A9, 45, FF, 00 ... ]. The trait std::fmt::UpperHex is not implemented for slices (so I can't use std::fmt::format). Rust has the serialize::hex::ToHex trait, which converts &[u8] to a…
Aleksandr
  • 1,303
  • 2
  • 11
  • 19
75
votes
13 answers

Python conversion from binary string to hexadecimal

How can I perform a conversion of a binary string to the corresponding hex value in Python? I have 0000 0100 1000 1101 and I want to get 048D I'm using Python 2.6.
sylvain
  • 759
  • 1
  • 5
  • 3
74
votes
5 answers

Does style="color: #FFF;" render as #F0F0F0 or #FFFFFF?

When defining colors using "shorthand hexidecimal" (style="color: #FFF;"), is there a defined method for expanding the shorthand? (style="color: #F0F0F0;" or style="color: #FFFFFF;") Do all browsers use the same expansion method? Is this behavior by…
Dolph
  • 49,714
  • 13
  • 63
  • 88
72
votes
8 answers

Write byte at address (hexedit/modify binary from the command line)

Is there any straightforward way to modify a binary from the commandline? Let's say I know that my binary contains 1234ABCD and I want to change it to 12FFABCD or FFFFABCD or maybe even FF34FFABC0 (you get the idea) :-) How might I achieve that…
Josh
  • 721
  • 1
  • 5
  • 4
72
votes
13 answers

Are there any good reasons for using hex over decimal for RGB colour values in CSS?

rgb(255,255,255) notation has been available since CSS1. But #ffffff seems to be vastly more popular. Obviously it's slightly more compact. I know that hex is more closely related to the underlying bytes, and understand that there would be…
e100
  • 1,603
  • 2
  • 14
  • 21
71
votes
8 answers

PHP convert string to hex and hex to string

I got the problem when convert between this 2 type in PHP. This is the code I searched in google function strToHex($string){ $hex=''; for ($i=0; $i < strlen($string); $i++){ $hex .= dechex(ord($string[$i])); } return…
JoeNguyen
  • 1,049
  • 2
  • 11
  • 15
70
votes
10 answers

How to print integer literals in binary or hex in haskell?

How to print integer literals in binary or hex in haskell? printBinary 5 => "0101" printHex 5 => "05" Which libraries/functions allow this? I came across the Numeric module and its showIntAtBase function but have been unable to use it correctly. >…
TheOne
  • 10,819
  • 20
  • 81
  • 119
69
votes
7 answers

'scanHexInt32' was deprecated in iOS 13.0

What is alternate of scanHexInt32 in iOS 13 (Swift 5+)? extension UIColor { //-------------------------------------------- class func hexColor(hex:String) -> UIColor { var cString:String = hex.trimmingCharacters(in:…
Krunal
  • 77,632
  • 48
  • 245
  • 261