Binary Systems
Combine together
Words are made of letters (University etc) Numbers are made of digits (4241 etc)
Binary System
Only 0 and 1 digits Can be easily implemented in electronic circuits
1 / 47
Digit Position
Integer & fraction
-1
-2
5 1 2
100 10 1
7 4
0.1 0.01
Digit Weight
Weight = (Base) Position
Magnitude
Sum of Digit x Weight
500
10
0.7 0.04
d2*B2+d1*B1+d0*B0+d-1*B-1+d-2*B-2
Formal Notation
(512.74)10
2 / 47
Weights
Weight = (Base) Position
64
1/8 1/64
5 1 2
2
2
7 4
-1
0 -1
Magnitude
Sum of Digit x Weight
1
1
-2
-2
5 *8 +1 *8 +2 *8 +7 *8 +4 *8
=(330.9375)10 (512.74)8
Formal Notation
3 / 47
Weights
Weight = (Base)
Position
1/2 1/4
1 0 1
2 1
1
0 1
-1
0 -1
-2
-2
Magnitude
Sum of Bit x Weight
1 *2 +0 *2 +1 *2 +0 *2 +1 *2
=(5.25)10 (101.01)2
1011 11000101
4 / 47
Weights
Weight = (Base) Position
256
16
1/16 1/256
1 E 5
2
2 1
7 A
-1
-1
Magnitude
Sum of Digit x Weight
0
0
-2
-2
=(485.4765625)10 (1E5.7A)16
Formal Notation
5 / 47
The Power of 2 n 0 1 2 3 4 5 6 7 2n 20=1 21=2 22=4 23=8 24=16 25=32 26=64 27=128 n 8 9 10 11 12 20 30 40 2n 28=256 29=512 210=1024 211=2048 212=4096 220=1M 230=1G 240=1T
Mega Giga Tera
6 / 47
Kilo
7 / 47
(2)10
8 / 47
= (10)2
0 1
9 / 47
1 0 0 1 0
1 1 0 1
1 0 0
Octal (Base 8)
Evaluate Magnitude
Binary (Base 2)
Decimal (Integer) to Binary Conversion Divide the number by the Base (=2) Take the remainder (either 0 or 1) as a coefficient Take the quotient and repeat the division
Example: (13)10
Quotient Remainder Coefficient
6 3 1 0
1 0 1 1
a0 = 1 a1 = 0 a2 = 1 a3 = 1
LSB
12 / 47
. . .
25 5 0
175 / 8 = 21 / 8 = 2 /8=
21 2 0
7 5 2
a0 = 7 a1 = 5 a2 = 2
Answer:
Example: (0.3125)10
Integer Fraction Coefficient
. .
5 0
a-1 = 2 a-2 = 4
Octal 0 1 2 3 4 5 6
( 1 0 1 1 0 . 0 1 )2
( 2
. 2 )8
Hex
0 1 2 3 4 5 6 7 8 9 A B C D E F
Binary
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
( 1 0 1 1 0 . 0 1 )2
(1
. 4 )16
( 2
Assume Zeros
2 )8
Assume Zeros
( 0 1 0 1 1 0 . 0 1 0 )2
(1
4 )16
17 / 47
Octal
00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17
Hex
0 1 2 3 4 5 6 7 8 9 A B C D E F
18 / 47
Take 1s complement then add 1 Toggle all bits to the left of the first 1 from the right Example: Number:
10110000 + 1 01010000
10110000
1s Comp.: 0 1 0 0 1 1 1 1
01010000
20 / 47
3 Systems
Signed Magnitude 1s Complement 2s Complement All three use the left-most bit to represent the sign: 0 1 positive negative
21 / 47
Signed Magnitude Representation Magnitude is magnitude, does not change with sign S
(+3)10 (3)10
Magnitude (Binary)
( 0 0 1 1 )2 ( 1 0 1 1 )2 Sign Magnitude
Cant include the sign bit in Addition 0 0 1 1 (+3)10 + 1011 1110 (3)10 (6)10
22 / 47
1s Complement Range 4-Bit Representation 2 = 16 Combinations 7 Number + 7 23+1 Number +23 1 n-Bit Representation 2n1+1 Number +2n1 1
4
Decimal 1s Comp.
+7 +6 +5 +4 +3 +2 +1 +0 0 1 2 3 4 5 6 7 0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000
24 / 47
1 0000
2s Complement Range 4-Bit Representation 2 = 16 Combinations 8 Number + 7 23 Number + 23 1 n-Bit Representation 2n1 Number + 2n1 1
4
Decimal 2s Comp.
+7 +6 +5 +4 +3 +2 +1 +0 1 2 3 4 5 6 7 8 0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000
26 / 47
1s Comp. -7 N +7
0
2s Comp. -8 N +7
0
Binary
1
Binary
1 1
Binary
Binary
1s Comp.
2s Comp.
27 / 47
Binary Subtraction Using 1s Comp. Addition Change Subtraction to Addition If Carry = 1 then add it to the LSB, and the result is positive (in Binary) If Carry = 0 then the result is negative (in 1s Comp.) (5)10 (1)10 (+5)10 + (-1)10 0101 + 1110 1 0011 + 0100 +4 (5)10 (6)10 (+5)10 + (-6)10 0101 + 1001 0 1110 1110 1
28 / 47
Binary Subtraction Using 2s Comp. Addition Change Subtraction to Addition If Carry = 1 ignore it, and the result is positive (in Binary) If Carry = 0 then the result is negative (in 2s Comp.) (5)10 (1)10 (+5)10 + (-1)10 0101 + 1111 1 0100 +4 (5)10 (6)10 (+5)10 + (-6)10 0101 + 1010 0 1111 1
29 / 47
Binary Coded Decimal Would it be easy for you if you can replace a decimal number with an individual binary code?
Such as 1910 = Code1 Code9
Decimal 0 1 2 3 4 5 6 7 8 9 BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
31 / 47
351
0011 0101 0001
32 / 47
5 8
0101
+ 3
+ 0011 1000
If the result is two decimal digits ( 10 ), then binary addition gives invalid combinations Example:
5 + 5 10
0001 0000
BCD Addition If the binary result is greater than 9, correct the result by adding 6 5 + 5 10 0101 + 0101 1010 + 0110 0001 0000
Two Decimal Digits
34 / 47
0
4
0
2
1
1
8 +
0 +
0 +
1 =
35 / 47
8,4,2,1
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
8,4,-2,-1
0000 0111 0110 0101 0100 1011 1010 1001 1000 1111
Excess3
0011 0100 0101 0110 0111 1000 1001 1010 1011 1100
36 / 47
Gray Code
The Gray code is unweighted and is not an arithmetic code. One bit changes from one code to the next code Different than Binary Decimal Gray
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000
Binary
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
37 / 47
38 / 47
39 / 47
7-bit Code
1000001 1000010
Z a b
. . .
. . .
z @ ? +
. . .
. . .
Even Odd
1 0
0 1 1 1 0 1 1 1
0 1
1 0 0 0 0 0 1 1 0 0 0 0 0 1
Parity
1 0 1 0 1 0 0 0
1 0 1 0 1 Parity Generator
1 0 0 0 1 Parity Checker
42 / 47
then then
Binary Logic
Truth Tables, Boolean Expressions, and Logic Gates
AND
x 0 0 1 1 y 0 1 0 1 z 0 0 0 1 x 0 0 1 1
OR
y 0 1 0 1 z=x+y z 0 1 1 1
NOT
x 0 1 z 1 0
z=xy=xy
z = x = x
x y
x y
z
44 / 47
Logic Signals Binary 0 is represented by a low voltage (range of voltages) Binary 1 is represented by a high voltage (range of voltages) The voltage ranges guard against noise
Switching Circuits
AND
OR
46 / 47
Summary
Binary numbers are made of binary digits (bits) Binary numbers can also be represented in octal and hexadecimal Conversion between number systems Addition, subtraction, and multiplication in binary Signed numbers are represented in 3 codes: signed magnitude, 1s complement, or 2s complement 2s complement code is most important (only 1 representation for zero) Other number codes exits, ASCII code is used to represent characters (such as those on the keyboard)
47 / 47