# Hex question

• 01-17-2008
John_L
Hex question
I know this is probably a stupid question...

x636F 6465 => Hex number

Can I look at each number/letter individually and write the corresponding decimal value? Since F is the only value which won't be identical, can I just insert 15 (it's corresponding decimal value) and have the number in decimal form? I want to convert it into binary....
• 01-17-2008
Dino
Quote:

Originally Posted by John_L
I know this is probably a stupid question...

Not stupid - but perhaps poorly phrased.

Quote:

x636F 6465 => Hex number

Can I look at each number/letter individually and write the corresponding decimal value?
You can do anything you want. What's your overall objective?

Quote:

Since F is the only value which won't be identical,...
Huh? Not sure I understand this. If I follow your logic, why isn't the 3 also unique???

Quote:

...can I just insert 15 (it's corresponding decimal value) and have the number in decimal form?
Well, F is 15, if it's in the lowest nibble.

Quote:

I want to convert it into binary....
Then all you need are bit patterns to replace the values. A little tight loop that spits out a 1 or a 0 based on the result of a BITWISE AND should work nicely. Test, output the 1 or 0, shift, repeat.

Todd
• 01-17-2008
John_L
What about negative numbers if I were to use two's complement? -1 or -432 in hexadecimal form? I have the algorithm down for positive decimal numbers to hex and binary...not sure about the negative ones for hex though (binary is easy).
• 01-17-2008
Dino
What do you care about negative numbers when converting from a base 16 representation of a base 2 number system?
• 01-17-2008
foxman
Here's a way to convert a negative decimal number to a two-complement's hexadecimal representation
Code:

``` -1 =  < take the absolute value of -1, which is 1 >  1 =  < transform it in hexadecimal >  0x0001  (let's say we are working with 16-bits words) =  < negate (one complement or 15 complement if you are staying in base 16) >  0xFFFE =  < add 1>  0xFFFF```
Example with another number
Code:

``` -473 =  473 =  0x01D9 =  0xFE26 =  0xFE27```
• 01-17-2008
brewbuck
Quote:

Originally Posted by John_L
I know this is probably a stupid question...

x636F 6465 => Hex number

Can I look at each number/letter individually and write the corresponding decimal value? Since F is the only value which won't be identical, can I just insert 15 (it's corresponding decimal value) and have the number in decimal form? I want to convert it into binary....

What does decimal have to do with anything? Anyway, hex to binary is easy enough to do in your head: 636F6465 = 01100011011011110110010001100101