# 210 Notes on Fixed Point Numbers

The electronic circuitry used for adding unsigned integers can also be used to add fractional numbers. As with signed integers, we need to impose a new interpretation on the bit patterns to achieve this.

One part of the computer word is chosen as the fractional part, and the other part is the integer part.

Example: 8-bit integer. Decide to treat last 4 bits as fraction part:

```1011.0110 = 1*2^3 + 0*2^2 + 1*2^1 + 1*2^0
+ 0*2^-1 + 1*2^-2 + 1*2^-3 + 0*2^-4
```
I.e. the number is 11.375

```Powers of 2:
3	8
2	4
1	2
0	1
-1	0.5
-2	0.25
-3	0.125
-4	0.0625
```

```  1011.0110	  11.375	[  182
+ 0011.1010	+  3.625        +  58
= 1111.0000	= 15.000	 = 240 ]
```
Great! Ordinary unsigned arithmetic works.

[ Can you make signed fixed-point numbers? ]

### Multiplication

Need to right-shift answer 4 places (or shift numbers before multiply)
```  0011.1010	   3.625
x 0000.0100	 x 0.250
1110.1000 (requires right shift 4 places)
= 0000.1110	 = 0.875
```
Actual answer is 0.90625; we lost a low-order bit in the right shift.