Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
,. How to decode binary to hex?
Posted
Updated 8-Jun-11 20:25pm
v2
Comments
Emilio Garavaglia 9-Jun-11 2:25am    
Title changed.

It's not "decode". Everything is binary, including hex. The term "hexadecimal" or "decimal" can only be related to string as a human-readable representation of numbers. The numbers as numeric types are always binary. Strings are binary, too, but they can be readable, say, in a text editor.

There are no single way to represent numeric data. For example, data of 64 bits can be represented in a string as 64 characters '0' or '1', as 8 separate bytes each represented by a decimal or integer value in the form of '128' or 'A2', or a signed or unsigned long integer, or a floating-point double-precision value. As there is not single interpretation of the binary data, the question does not have a certain sense.

—SA
 
Share this answer
 
Comments
Albert Holguin 9-Jun-11 0:07am    
my 5...
Sergey Alexandrovich Kryukov 9-Jun-11 0:21am    
Thank you, Albert.
--SA
Albert Holguin 9-Jun-11 0:23am    
you're welcome... I was answering in a similar fashion.. when I finished typing, there was a bunch of solutions up (only Amits was there)... maybe I need to type faster! lol
Sergey Alexandrovich Kryukov 12-Jun-11 18:14pm    
I feel I arrive the latest in most cases if more experts are answering. Who cares? :-)
--SA
Wild-Programmer 9-Jun-11 4:13am    
Awesome :) 5+
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 8-Jun-11 23:53pm    
It might be helpful, my 5, but to say the truth, the question does not make certain sense.
I try to explain in it my answer, please see.
--SA
Wild-Programmer 9-Jun-11 4:13am    
Thanks :)
Hexadecimal is commonly used because of the fact that it four binary bits happen to be one hexadecimal character (since its base 16 and four bits give you values 0-15).

Therefore, to go from binary to hex (random binary sequence):
1001 1101 1111 0010
---9----D----F----2 (put dashes for spacing)

Now, if you want to do this programmatically, the hex interpretation is merely a human readable form. All numbers are stored as binary internally, so conversion to hex really doesn't provide anything significant besides readability.
int value = 11; //<- decimal 11, 
//internally stored as 00000000 00000000 00000000 00001011 (arbitrary byte order)
CString hex_val;
hex_val.Format("%X",value); //<- hex B
 
Share this answer
 
v2
Comments
Albert Holguin 9-Jun-11 0:07am    
univote? really?
Sergey Alexandrovich Kryukov 9-Jun-11 0:23am    
My 5.
--SA
Albert Holguin 9-Jun-11 0:25am    
thanks :)
If you are seraching for any c++ fn that does it.
use
void HexFromBin(
  LPBYTE pb,
  int cb,
  LPSTR sz
);


see http://msdn.microsoft.com/en-us/library/cc765674.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900