Solved

convert hexadecimal to bytes

Posted on 2014-03-20
5
273 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MaxSpan challenge 9 122
sumHeights  challenge 17 78
How to get the score in percent of an activity? 7 67
Work with App store 7 87
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

680 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