Go Home Go Home

Computer Coding

Most people know that computer stores data in bit pattern using 1s and 0s.
But how can computer do this?

Listen it

We'll look at integer first

Fixed Point Representation

  • Sign-and-magnitude representation
    • The left most bit represents the sign of number
      ("0" stands for "+" while "1" stands for "-")
    • The remaining bit represent the binary equivalent of the magnitude of the number
  • 2's complement representation

    Algorithm:

    • Convert the denary number to binary code
    • If it is +ve, you are finished, else conduct 3 & 4
    • Changing all 0s to 1s and all 1s to 0s
    • Add 1 to the result binary code.
  • Excess code representation

    Algorithm (take 128 excess code as example):

    • Add 128 to the denary integer
    • Convert the result value to binary
We can use use the above method to represent number with decimals. We, however, seldom use fixed point representation. We use floating point representation instead.

Floating Point Representation

Floating Point Bit Pattern Divides in several parts

  • Sign of mantissa ("1" = "-", "0" = "+")
  • Magnitude of mantissa
  • Exponent (can be represented by sign-snd-magnitude, 2's complement or excess code)

The sign of the number = Sign of mantissa
The value of the number = Magnitude of mantissa * 2 exponent


Proceed to : Machine Instruction