Solved

convert hexadecimal to bytes

Posted on 2014-03-20
5
267 Views
Last Modified: 2014-03-21
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
Comment
Question by:TRocex
5 Comments
 
LVL 3

Expert Comment

by:ola_erik
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:
http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html
0
 

Author Comment

by:TRocex
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

by:ola_erik
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

by:cristiantm
cristiantm earned 300 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

by:
TommySzalapski earned 200 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now