Binary Numbers
Most humans use the decimal number system for performing simple mathmatics. In this system we describe numbers using digits that can define 10 different values: 0,1,2,3,4,5,6,7,8,9. In order to describe larger numbers we use columns each defining a value 10 times bigger than the previous column. Hence the number 154 is written:100's | 10's | 1's |
---|---|---|
1 | 5 | 4 |
Although in electronics it is possible to describe a value by means of a variable voltage, say 1V for 1, 5V for 5 etc. It is difficult to manipulate and perform mathmatical operations with, what is called, analogue voltages. It is easier and more reliable to use a simple on or off system. The binary number system is a number system that has only two digits: 0 and 1. Again it uses colums to describe larger numbers were each column is 2 times bigger than the previous column. In this for the decimal number 154 is written as 10011000 in binary.
128's | 64's | 32's | 16's | 8's | 4's | 2's | 1's |
---|---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
As it is a bit long winded to write numbers in binary, binary numbers are often written in hexidecimal form. Hexidecimal numbers have digits that can define 16 different values: 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f. A feature of base 16 is that base 2 is a multiple of it so it is easy to translate between binary and hexidecimal versions of a number.
256's | 16's | 1's |
---|---|---|
0 | 9 | A |
In a computer numbers have to be stored in memory cells and each column, or bit, will need a seperate cell. Also when a binary number is transfered it will need as many wires as there are columns or bits. To reduce the complexity of a computer the number of bits is restricted. A simple micro-processor as used in a watch may only use 8 bits. A personal computer will offen use 32bits and a large number crunching computer may use 64bits. An 8bit value is defined as a Byte and can store numbers from 0 through to 255. If it is used to store a signed number then it can store from -128 to 127.
Name | Number of bits | Value Range |
---|---|---|
8 | 0 - 255 | |
16 | 0 - 65535 | |
32 | 0 - 4294967299 |
Bit values can be stored within a computer in memory locations or input or output through "pins" on a computer chip.
How about negative numbers ? A computer uses a coding scheme called "two's compliment" to store a negative number. In this case the uppermost bit of a byte, word or double word is used as a sign bit. If this bit is set to "1" then its value is taken as minus its normal column value. Below shows the decimal value "-100" in a signed byte.
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 1 | 1 | 1 | 0 | 0 |
In a computer a memory location can be used as an "unsigned" value or a "signed" value.
Exersises
- Write the number 28 in binary.
- Write the number 120 in binary.
- What is the binary number 01010101 in decimal.
- What is the binary number 0111111 in decimal.
- What is the sum of 0001 and 0011 in binary.
- What is the mulplication of 0001 and 0010 in binary.