x
Solved

# convert hexadecimal to bytes

Posted on 2014-03-20
Medium Priority
431 Views
I took a output like in hexadecimal  (0xCF0400000100) and I want to convert it to a file and page address..according to a book I read, it says ""In hexadecimal notation,
each set of two hexadecimal digits represents a byte. I first had to swap the bytes to get
00 01 00 00 04 CF"" so I could not understand how it wrote 0xCF0400000100 as 00 01 00 00 04 CF...I think it converted a hex to binary so  is that possible?. if yes,could you please explain as detail?
0
Question by:TRocex

LVL 3

Expert Comment

ID: 39941744
Decimal:

Every digit is between 0 and 9 as in 01234567890 (10 different choices)
how to get the value from decimal number?
23465

5*1
6*10
4*10*10
3*10*10*10
etc

Hex:

Every "digit" is between 0 and F as in 01234567890ABCDEF (16 choices)
the value from hex number:

F3A5
5*1
A(10)*16
3*16*16
F(15)*16*16*16
etc

Binary:

every digit is between 0 and 1 as in 01 (2 digits)

value from binary number:
011001
1*1
0*2
0*2*2
1*2*2*2
1*2*2*2*2

etc

thus generalized:

digit(position)*base^position
where positon starts with 0 at rightmost place
base is 10 for decimal, 16 for hex, 2 for binary, can be anything

See here for automatic conversion, playing -> understanding:
0

Author Comment

ID: 39941804
many thanks I agree with you but the thing what I dont understand, In hexadecimal notation,
how the hex value 0xCF0400000100 can be written as 00 01 00 00 04 CF.. because the book says " each set of two hexadecimal digits represents a byte. I first had to swap the bytes to get
00 01 00 00 04 CF"  could you please explain that me?
0

LVL 3

Expert Comment

ID: 39941844
1. googling the number yields some results from MS SQL 2008.

the 0x is not part of the value
As long as you keep track of how you represent the serie you can of course write them in any sequence you want.

as in

10 45 67 87 23
(10,45,67,87,23)
1045678723

or

23
87
67
45
10

or

23 87 67 45 10

Google search for 0xCF0400000100;
http://tinyurl.com/pvmospy
0

LVL 3

Assisted Solution

cristiantm earned 900 total points
ID: 39941993
The byte order thing, that is your question, looks like an endianess thing. Some systems are bigendian, that is, the most significant byte comes first, and others are little endian, when the less significant comes first.

So you are taking the value 0xCF0400000100 and putting it on on memory as little endian data, that is, in an "reversed" order.

This might help:
http://en.wikipedia.org/wiki/Endianness
0

LVL 37

Accepted Solution

TommySzalapski earned 600 total points
ID: 39942966
Yes. The byte order swapping is just due to the endianness of the system. The (little endian) system will store the number with the smallest byte first (kind of like if we wrote decimal numbers backwards). This is to make certain operations faster (since the first byte it sees is always the "ones" byte). When it displays the number for a human to read, though, it flips the order because that's how we are accustomed to reading numbers (with the "ones" place on the far right). What makes it confusing perhaps is that it swaps the bytes, not the hex digits.

Note that nothing is being "converted to binary." It's already in binary in the computer. Hexadecimal is just a convenient way of displaying the binary byte values to us humans. But two hex digits make one byte, so any time you see hex, think of the pairs of characters as inseparable. Putting spaces between them as you did is very helpful.
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Join & Write a Comment Already a member? Login.

This article seeks to propel the full implementation of geothermal power plants in Mexico as a renewable energy source.
This article provides a brief introduction to tissue engineering, the process by which organs can be grown artificially. It covers the problems with organ transplants, the tissue engineering process, and the current successes and problems of the tec…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
###### Suggested Courses
Course of the Month11 days, 10 hours left to enroll

#### 601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.