Hex representation of S1.14 and S1.9format

Software questions and issues with the FV-1

Moderator: frank

Post Reply
Sweetalk
Posts: 141
Joined: Thu Oct 15, 2009 5:13 am

Hex representation of S1.14 and S1.9format

Post by Sweetalk »

I was studying the different formats for the signed fixed point values in the SpinASM Manual and came across the following table:

Code: Select all

S1.14
Real -2      -0.00006103516   0            0.00006103516 1.99993896484
Hex $8000 $FFFF               $0000      $0001             $7FFF
S1.9
Real -2       0.001953125  0        0.001953125   1.998046875
Hex $400    $7FF            $000   $001              $3FF
For the -2 decimal uses $8000, equivalent to "-0" ($1000_0000_0000), so far so good. I don't understand why for the -LSB (-0.00006103516) uses $FFFF instead of $8001 that will be %1000_0000_0000_0001 the sign bit on 1, the integer bit on 0 and the LSB on 1. Or the negative numbers are going backwards from FFFF (65535 in decimal) to the 8000 (32768)?.
Same applies for the S1.9
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: Hex representation of S1.14 and S1.9format

Post by frank »

Generally numbers in hex or binary are represented in a format called "2's complement", what you are thinking (0x8000 is "-0") is called "sign-magnitude". Google "2's complement" to learn about it but a few reasons we use it are:

Only a +0, no -0 in the system

Direct addition and subtraction of numbers. Try adding a -1 and a +1 in sign-magnitude, not going to get 0 but in 2's comp you will.

MUCH easier to detect overflow in 2's comp math by examining sign bits of the values.
Frank Thomson
Experimental Noize
Sweetalk
Posts: 141
Joined: Thu Oct 15, 2009 5:13 am

Re: Hex representation of S1.14 and S1.9format

Post by Sweetalk »

Oh, how can I forgot the 2s complement!!!. Thanks Frank, all clear now. :mrgreen:
Post Reply