d-daybuttercup
d-daybuttercup

Reputation: 21

How to interpret an 8-bit hex value as unsigned decimal numbers?

This is a basic question and probably very easy but I am really confused.

I have an 8-bit hex number 0x9F and I need to interpret this number as an unsigned decimal number.

Do I just convert that to the binary form 1001 1111? and then the decimal number is 159?

I'm sorry if this question is trivial but my professor said I couldn't e-mail him questions and I don't know anyone in my class. He made it sound like when converting from hex to binary that it will be the 2's compliment. So I don't know if I need to convert it back to normal or not before converting to decimal.

We had a signed decimal number and converted it to binary, then took the 2's compliment and converted to hex. Is that only with signed numbers?

Upvotes: 0

Views: 4806

Answers (1)

paxdiablo
paxdiablo

Reputation: 881153

It's simply 9 * 16 + F where F is 15 (the letters A thru F stand for 10 thru 15). In other words, 0x9F is 159.

It's no different really to the number 314,159 being:

  3 * 100,000 (10^5, "to the power of", not "xor")
+ 1 *  10,000 (10^4)
+ 4 *   1,000 (10^3)
+ 1 *     100 (10^2)
+ 5 *      10 (10^1)
+ 9 *       1 (10^0)

for decimal (base 10).

The signedness of such a number is sort of "one level up" from there. The unsigned value of 159 (in 8 bits) is indeed a negative number but only if you interpret it as one.

Upvotes: 2

Related Questions