4. Negative Binary number & whole numbers

Negative numbers

The last page only described positive numbers. But negative numbers need to be represented as well.

To represent a negative number the most significant bit is used to indicate the sign of the number.

-128 64 32 16 8 4 2 1
1 1 0 1 0 0 0 0

With this rule in place, if a 1 is present in the leftmost position of the binary number, then it means that the rest of the number is negative.

Whole numbers

A very efficient way of representing whole numbers is to use 'integers'.

An integer can only represent whole numbers and are not concerned with decimal or real numbers that have a decimal point.

Note that the software program must know the format being used. This is usually defined when setting up a variable like this.

define x as unsigned integer
define calc as signed integer

An 8 bit 'unsigned integer' assumes that the entire number is positive. So 10000001 is +129 but if the data is a 'signed integer' then 1000001 is a negative integer.

Some computer languages assume that all integers are unsigned unless told otherwise.

So the most significant bit indicates the sign of the number. But what about the rest of the number - how is this used? Good question.

There are a number of ways to use the rest of the bits to represent a negative number. And one of the most useful methods is called 'twos complement' which is covered on the next page.



Copyright © www.teach-ict.com