0
votes

I understand how two's-complement works. I also understand how signed magnitude and one's-complement work, and the advantages that two's-complement has over the other encoding methods.

What I can't figure out, is if I'm asked to convert a signed hex number to dec, e.g. 0xF3C645AC, how do I figure out which encoding method it's using?

1
you don't have to know anything about how a number is encoded to change it from one base to another. If you want to decode before converting to decimal, then you can't do that unless you know how it's encoded. - Red Alert
@RedAlert That may be true for positive numbers, but if the number is negative, and it was encoded with one's-complement, and I decode it with two's-complement, I will get the wrong answer. - 1.618
decoding a number is not the same as representing it as a different number base. If you want to decode a number, yes you need to know how it was encoded. That information is not stored in the number itself. - Red Alert

1 Answers

1
votes

You can't.

Those interpretation schemes are not encoded themselves in the data.

Machine don't usually implement two kinds of integer representation on hardware level thoug, so you can safely assume the number is being represented the same way all other integers in the context are.

...in the case it's some exercise/homework, well, interpret for all the possibilities, the teacher will be glad :)