Solved

convert hexadecimal to bytes

Posted on 2014-03-20
5
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
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…
Suggested Courses

624 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