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
118
votes
18 answers

Convert hex color to RGB values in PHP

What would be a good way to convert hex color values like #ffffff into the single RGB values 255 255 255 using PHP?
user123_456
  • 5,635
  • 26
  • 84
  • 140
117
votes
19 answers

How do you convert a byte array to a hexadecimal string in C?

I have: uint8 buf[] = {0, 1, 10, 11}; I want to convert the byte array to a string such that I can print the string using printf: printf("%s\n", str); and get (the colons aren't necessary): "00:01:0A:0B" Any help would be greatly appreciated.
Steve Walsh
  • 6,363
  • 12
  • 42
  • 54
113
votes
9 answers

Decorating Hex function to pad zeros

I wrote this simple function: def padded_hex(i, l): given_int = i given_len = l hex_result = hex(given_int)[2:] # remove '0x' from beginning of str num_hex_chars = len(hex_result) extra_zeros = '0' * (given_len - num_hex_chars)…
jon
  • 5,986
  • 5
  • 28
  • 35
110
votes
6 answers

How to convert an Int to Hex String in Swift

In Obj-C I used to convert an unsigned integer n to a hex string with NSString *st = [NSString stringWithFormat:@"%2X", n]; I tried for a long time to translate this into Swift language, but unsuccessfully.
boscarol
  • 1,901
  • 2
  • 15
  • 29
101
votes
12 answers

What's 0xFF for in cv2.waitKey(1)?

I'm trying understand what 0xFF does under the hood in the following code snippet: if cv2.waitKey(0) & 0xFF == ord('q'): break Any ideas?
Dora
  • 1,163
  • 2
  • 9
  • 11
100
votes
5 answers

Write bytes to file

I have a hexadecimal string (e.g 0CFE9E69271557822FE715A8B3E564BE) and I want to write it to a file as bytes. For example, Offset 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 00000000 0C FE 9E 69 27 15 57 82 2F E7 15 A8 B3 E5 64 BE …
John Doe
  • 9,843
  • 13
  • 42
  • 73
95
votes
7 answers

Integer to two digits hex in Java

I need to change a integer value into 2-digit hex value in Java.Is there any way for this. Thanks My biggest number will be 63 and smallest will be 0. I want a leading zero for small values.
Salih Erikci
  • 5,076
  • 12
  • 39
  • 69
95
votes
7 answers

Objective-C parse hex string to integer

I would like to know how to parse a hex string, representing a number, in Objective-C. I am willing to use both an objective, or a C-based method, either is fine. example: #01FFFFAB should parse into the integer: 33554347 Any help would be…
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
94
votes
17 answers

Generating a random hex color code with PHP

I'm working on a project where I need to generate an undefined number of random, hexadecimal color codes…how would I go about building such a function in PHP?
joshdcomp
  • 1,618
  • 3
  • 19
  • 26
94
votes
7 answers

Convert string to hex-string in C#

I have a string like "sample". I want to get a string of it in hex format; like this: "796173767265" Please give the C# syntax.
Dariush Jafari
  • 5,223
  • 7
  • 42
  • 71
92
votes
6 answers

Hex colors in Android are sometimes eight digits. How? What is the difference between #FFFFFF and #FFFFFF00?

I sometimes have seen in examples where the coloring in Android is done as #FF191919. I mean an eight-digit hex number. But it should only be a six-digit number. How are they related? If I want to convert a six-digit number to a eight-digit number,…
Vinod
  • 31,933
  • 35
  • 96
  • 119
90
votes
8 answers

Javascript: Unicode string to hex

I'm trying to convert a unicode string to a hexadecimal representation in javascript. This is what I have: function convertFromHex(hex) { var hex = hex.toString();//force conversion var str = ''; for (var i = 0; i < hex.length; i += 2) …
user429620
89
votes
10 answers

Java converting int to hex and back again

I have the following code... int Val=-32768; String Hex=Integer.toHexString(Val); This equates to ffff8000 int FirstAttempt=Integer.parseInt(Hex,16); // Error "Invalid Int" int SecondAttempt=Integer.decode("0x"+Hex); // Error "Invalid Int" So,…
Rich S
  • 3,248
  • 3
  • 28
  • 49
88
votes
6 answers

How to create a System.Drawing.Color from its hexadecimal RGB string?

I want to create a System.Drawing.Color from a value like #FF00FF or FF00FF without needing to write code for that. There is any .NET built-in parser for that?
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
83
votes
3 answers

Python Hexadecimal

How to convert decimal to hex in the following format (at least two digits, zero-padded, without an 0x prefix)? Input: 255 Output:ff Input: 2 Output: 02 I tried hex(int)[2:] but it seems that it displays the first example but not the…
VikkyB
  • 1,440
  • 4
  • 16
  • 26