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
179
votes
13 answers

Print a string as hexadecimal bytes

I have this string: Hello, World! and I want to print it using Python as '48:65:6c:6c:6f:2c:20:57:6f:72:6c:64:21'. hex() works only for integers. How can it be done?
Eduard Florinescu
  • 16,747
  • 28
  • 113
  • 179
178
votes
3 answers

How do I convert hex to decimal in Python?

I have some Perl code where the hex() function converts hex data to decimal. How can I do it on Python?
Sir D
  • 2,164
  • 2
  • 17
  • 21
173
votes
8 answers

Hexadecimal To Decimal in Shell Script

Can someone help me to convert a hexadecimal number to decimal number in a shell script? E.g., I want to convert the hexadecimal number bfca3000 to decimal using a shell script. I basically want the difference of two hexadecimal numbers. My code…
VenkateshJN
  • 1,904
  • 2
  • 13
  • 16
172
votes
20 answers

How to convert numbers between hexadecimal and decimal

How do you convert between hexadecimal numbers and decimal numbers in C#?
Andy McCluggage
  • 37,618
  • 18
  • 59
  • 69
172
votes
7 answers

Visual Studio debugger - Displaying integer values in Hex

I'm using Visual Studio 2008 and I have just noticed that the debugger is displaying integer values as Hex when I hover over variables and also in the immediate window. I guess I must have hit a shortcut key accidently or something. Anyone had this…
fizzer
  • 2,239
  • 3
  • 17
  • 21
171
votes
28 answers

In Java, how do I convert a byte array to a string of hex digits while keeping leading zeros?

I'm working with some example java code for making md5 hashes. One part converts the results from bytes to a string of hex digits: byte messageDigest[] = algorithm.digest(); StringBuffer hexString = new StringBuffer(); for (int…
Eugene M
  • 47,557
  • 14
  • 38
  • 44
159
votes
10 answers

C++ convert hex string to signed integer

I want to convert a hex string to a 32 bit signed integer in C++. So, for example, I have the hex string "fffefffe". The binary representation of this is 11111111111111101111111111111110. The signed integer representation of this is: -65538. …
Clayton
  • 6,089
  • 10
  • 44
  • 47
157
votes
5 answers

What do numbers using 0x notation mean?

What does a 0x prefix on a number mean? const int shared_segment_size = 0x6400; It's from a C program. I can't recall what it amounts to and particularly what the letter x means.
Terry Li
  • 16,870
  • 30
  • 89
  • 134
153
votes
17 answers

Converting an RGB color tuple to a hexidecimal string

I need to convert (0, 128, 64) to something like this "#008040". I'm not sure what to call the latter, making searching difficult.
rectangletangle
  • 50,393
  • 94
  • 205
  • 275
151
votes
22 answers

Convert hex to binary

I have ABC123EFFF. I want to have 001010101111000001001000111110111111111111 (i.e. binary repr. with, say, 42 digits and leading zeroes). How?
aaaaaaaaaaaaaaaaaaa
135
votes
9 answers

Convert hex string to int

I am trying to convert a string that is 8 characters long of hex code into an integer so that I can do int comparison instead of string comparisons over a lot of different values. I know this is fairly trivial in C++ but I need to do it in Java. …
Roloc
  • 1,910
  • 2
  • 13
  • 16
128
votes
8 answers

Printing hexadecimal characters in C

I'm trying to read in a line of characters, then print out the hexadecimal equivalent of the characters. For example, if I have a string that is "0xc0 0xc0 abc123", where the first 2 characters are c0 in hex and the remaining characters are abc123…
Rayne
  • 14,247
  • 16
  • 42
  • 59
127
votes
13 answers

Convert decimal to hexadecimal in UNIX shell script

In a UNIX shell script, what can I use to convert decimal numbers into hexadecimal? I thought od would do the trick, but it's not realizing I'm feeding it ASCII representations of numbers. printf? Gross! Using it for now, but what else is…
skiphoppy
  • 97,646
  • 72
  • 174
  • 218
124
votes
5 answers

How to create python bytes object from long hex string?

I have a long sequence of hex digits in a string, such as 000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44 only much longer, several kilobytes. Is there a builtin way to convert this to a bytes object in python 2.6/3?
recursive
  • 83,943
  • 34
  • 151
  • 241
120
votes
23 answers

Converting A String To Hexadecimal In Java

I am trying to convert a string like "testing123" into hexadecimal form in java. I am currently using BlueJ. And to convert it back, is it the same thing except backward?
Keith