Binary
Most switching devices, such as a
light switch, only have two possible states - on and off. The same is true with
the millions of transistorised switches inside a computer. These two possible
states are represented mathematically as 1 or 0. The number system based upon
these two states is known as BINARY (or base 2).
With any number system we need a
“place” value. Decimal numbers increase from right to left from “units” to
“tens” to “hundreds”, etc. Each is an increasing power of 10, ie 101 then
102, then 103 . The same applies with binary numbers but
in this case we are dealing with powers of 2.
This system will therefore have a
range in binary from 00000000 to 11111111 that would be 0 to 255 in decimal.
Each of the Binary
digITs
(a 1 or a 0) is given the name BIT. Eight bits are normally referred to as a
BYTE (but it could be the number of bits required to represent a character. If
a computer system accesses data in larger chunks it is termed a WORD. 1024
bytes is a kilobyte.
If we wish to represent more than
255 (in decimal) more bits and bytes will be required. For instance, 16 bits
could represent the numbers up to 65535. If a computer stores data in 16 bit
“chunks” then it is said to have a “word-length” of 16 bits. Modern PC’s now
work with a word-length of 32 bits and even 64 bits.
To convert from decimal to binary
there are a number of methods eg repeated division by 2, with the remainder
being the binary digit.
example
Convert 123 to binary
123/2 = 61 remainder 1
61/2 = 30 remainder 1
30/2 = 15 remainder 0
15/2 = 7 remainder 1
7/2 = 3 remainder 1
3/2 = 1 remainder 1
1/2 = 0 remainder 1
So, reading from bottom to top
gives:
1 1 1 1 0 1 1
Normally this would be converted to
8 bits by adding a leading zero. ie
0 1 1 1 1 0 1 1
An alternative method would be to
repeatedly subtract, if possible, 128, 64, 32, etc from the original number and
then the numbers subtracted from the remainders. If subtraction can take place
then the bit it set to 1, if not it is set to 0.
So far we have only dealt with
"pure" binary numbers - we have treated them as a number without any
sign. The alternative is to use something called Sign and Magnitude.
In this system we have the most significant bit (or MSB) which is the
left-hand one that tells us if the number is positive or negative. If
there is a zero in there it is positive, a one represents negative. So
0 0 0 0 0 0 1 1 would mean +1
1 0 0 0 0 0 1 1 would mean -1
No comments:
Post a Comment