Fixed Point Numbers

Fixed Point Numbers

Introduction

  • Integers can be stored easily in memory as binary numbers
  • However fractions are more complicated
  • Fixed point numbers are a simple way of storing fractional numbers in which the integer and fractional parts are stored in separate portions of the data structure.
  • each portion has a fixed size.
    • as opposed to floating point numbers in which the sizes are more dynamic.

Example

  • We want to store the number 15.5
  • We can use a two-byte fixed point number for this
  • The first byte is used to store the integer part: 15
    • This is just a case of converting it to binary and padding so we have 8 bits: 00001111
  • The second byte is used to store the fractional part: 0.5
    • This byte is divided into 256 separate units, each representing 1/256
    • To store 0.5 we use 128/256
    • So we store 128 in the second byte
    • In binary this is 10000000
  • 15.5 is stored as 00001111 10000000