Upload
terri-short
View
40
Download
0
Embed Size (px)
Citation preview
65 Denary to Binary
Start by writing out the place values.124816326412
8
Then write 1s underneath the place values that add up to the denary number.
0 1 0 0 0 0 0 1
64 16 1 + + = 81
Binary to Denary
0 1 0 1 0 0 0 1
Start by writing the place values above each bit.124816326412
8
Then write out the place values of the 1s.
Finally add the numbers together.
Binary AdditionThe process of performing addition in binary is very similar to addition in denary.1 1 1 10 1 1 0 10 0 1 1 1 +1 0 1 0 0
Rules:0 + 0 = 00 + 1 = 11 + 1 = 0 carry 11 + 1 + 1 = 1 carry 1
0 1 1 0 01 0 1 1 1 +
1 1 1 0 01 0 1 0 1 +
OverflowWhen there isn’t enough room for a result, this is called an overflow and it produces an overflow error.
1 1 1 11 1 1 0 1
1 1 0 1 1 1 +1 1 0 1 0 0
No room for a carry, so it is lost and we get the wrong answer.Humans can easily work around this, but it isn’t so easy for a computer.
Binary SubtractionThe process of performing subtraction in binary is very similar to subtraction in denary.
1 1 0 00 1 0 0 -1 0 0 0
Rule:0 - 1 won’t go so borrow 10 (2) from the column to the left. 2 - 1 = 1.
10 10
1 1 0 10 1 1 1 -0 1 1 0
1 1 1 00 1 0 1 -
Sign and MagnitudeThis is the simplest method of representing negative numbers in binary. The most significant bit is the ‘sign bit’.
Sign bit 128 64 32 16 8 4 2 10 0 0 0 1 1 0 1 1 +2
71 0 0 0 1 1 0 1 1 -27
1 = minus 0 = plus
The Problem with Sign and MagnitudeThe problem with sign and magnitude is that addition doesn’t always work.
0 0 0 0 0 1 1 1 (+7)
1 0 0 0 0 1 0 1 (-5) +1 0 0 0 1 1 0 0 (-
12)
Two’s Complement
Two’s complement is an alternative method of representing negative numbers. This method works with binary addition.
The most significant bit is a minus number.-128 64 32 16 8 4 2 1
1 0 0 0 1 1 0 1
-128 + 8 + 4 + 1 = -115
Floating Point NumbersIn binary floating point numbers are split into two parts; the Mantissa and the Exponent.
Mantissa Exponent0111 1000 0000 0011
0 . 1 1 1 1 0 0 0
The mantissa contains the actual number and the exponent defines the position of the binary point.
Floating Point NumbersThe numbers to the right of the binary point define the fraction.
0 1 1 1 . 1 0 0 0In denary the number above is:
7 ½
1/2 1/4 1/8 1/168/16 4/16 2/16 1/16
HexadecimalProgrammers often use hexadecimal numbers as a shorthand for binary to save time. Hexadecimal (hex) numbers are based on the number 16. Each column has a value 16 times that of the one on its right.
place value 256 16 1
There are 16 different values available in hex:
Letters are used for values 10-15 to ensure that only single digits are used.
0 1 2 3 4 5 6 7 8 9 A B C D E F
Hexadecimal to Binary
Converting between hexadecimal and binary is particularly easy. You just take each character and convert it into the equivalent binary number.
Hex D B
Denary 13 11
Binary 1 1 0 1 1 0 1 1
In this example we will convert DB hex to binary.