[Math] Converting a negative decimal with fractions to binary and hex

arithmeticbinaryfractions

I am asking the question even though it has been answered before because I am looking at 3 different pages with 3 different answers right now.

I am wondering how to convert a negative decimal with a fraction, for example

$$-37.125$$

to binary and to hex in two's complement form.

I understand how to do this with a positive number, and I understand how to convert whole numbers into two's complement form.

From what I can tell, the process for the whole number will remain the same (convert to binary, switch zeros with ones, and add one).

However, I have no idea what to do for the fractional negatives because it doesn't seem like you can just treat it as a positive fraction and I tried converting it a couple of times into two's complement but can't get the proper answer by just switching zeros or something similar.

The answer needs to be represented in the form with the Most Significant Bit being a 1 to show it is negative. So the respective conversions would be

$$-37.125 \to 0b11011010.11100000 \to 0xDA.E0$$

Any hints to go to and from binary would suffice, since to and from hex is the same process once you know the binary.

Thank you very much for any help!

Best Answer

I don't know that this counts as an answer, but it is too much to say in a comment:

Actually, the change does help considerably to understand the question. But the answer is still dependent on the particular implementation. Different systems represent floating point numbers in different ways (even without considering Endianess). Most common (I believe - I am not a computer scientist), is to represent -37.125 exactly the same as 37.125, except for the sign bit $D$ being set. $37.125 = 0b100101.001$. The Exponent $E$ is determined by shifting this until only the leading 1 is to left of the radix $37.125 = 0b1.00101001 \times 2^5$, so $E = 5$. (I'll let you translate it to binary. Note that $E$ is a signed integer and normally written in 2s-complement - the only part of the expression that is.) Since the leading bit is always 1, there is no need to actually store it, so the significand $A = 0b00101001$, followed by however many other 0s you have room for.

However, whether this is the exact form you need it in, I cannot say.