Lec 01 - Digital Systems & Binary Numbers
Lec 01 - Digital Systems & Binary Numbers
• The possibilities:
Decimal Octal
Binary Hexadecimal
Basic rules
• To convert from b number system to decimal
Decimal
Decimal
Base
Decimal to Decimal (just for fun)
Decimal Octal
Binary Hexadecimal
Next slide…
Weight
Base
Binary to Decimal
Decimal Octal
Binary Hexadecimal
Binary to Decimal
• Technique
– Multiply each bit by 2n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example
Bit “0”
1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
Hexadecimal to Decimal
Decimal Octal
Binary Hexadecimal
Hexadecimal to Decimal
• Technique
– Multiply each bit by 16n, where n is the
“weight” of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example
Decimal Octal
Binary Hexadecimal
Decimal to Binary
• Technique
– Divide by 2, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant
bit)
– Second remainder is bit 1
– Etc.
Decimal to Binary cont.
• 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
13/ 2 = 6 1 a0 = 1
6 /2= 3 0 a1 = 0
3 /2= 1 1 a2 = 1
1 /2= 0 1 a3 = 1
Answer: (13)10 = (a3 a2 a1 a0)2 = (1101)2
MSB LSB
Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1
12510 = 11111012
Hexadecimal to Binary
Decimal Octal
Binary Hexadecimal
Hexadecimal to Binary
• Technique
– Convert each hexadecimal digit to a 4-bit
equivalent binary representation
Example
10AF16 = ?2
1 0 A F
10AF16 = 00010000101011112
Decimal to Hexadecimal
Decimal Octal
Binary Hexadecimal
Decimal to Hexadecimal
• Technique
– Divide by 16
– Keep track of the remainder
Example
123410 = ?16
16 1234
16 77 2
16 4 13 = D
0 4
123410 = 4D216
Binary to Hexadecimal
Decimal Octal
Binary Hexadecimal
Binary to Hexadecimal
• Technique
– Group bits in fours, starting on right
– Convert to hexadecimal digits
Example
10101110112 = ?16
10 1011 1011
2 B B
10101110112 = 2BB16
Binary − Hexadecimal
Hex Binary
• 16 = 24 0
1
0000
0001
Hexa-
Decimal Binary decimal
33
1110101
1AF
Hexa-
Decimal Binary decimal
33 100001 21
117 1110101 75
431 110101111 1AF
Fractions
p. 50
Exercise – Convert ...
Hexa-
Decimal Binary decimal
29.8
101.1101
C.82
Answer
Hexa-
Decimal Binary decimal
29.8 11101.110011… 1D.CC…
5.8125 101.1101 5.D
12.5078125 1100.10000010 C.82
Binary Addition (1 of 2)
• Two 1-bit values
A B A+B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
Binary Addition (2 of 2)
A B A×B
0 0 0
0 1 0
1 0 0
1 1 1
Multiplication (3 of 3)
1010 0111
0011
2. + 6. - 0010
1110 1010
0101
3. + 7. - 0111
0111 1110
1010
4. + 8. - 0100
Negative numbers
• How do we write negative binary numbers?
– Prefix numbers with minus symbol?
• 3 approaches:
– Sign and magnitude
– Ones-complement
– Twos-complement
–1 1000 0111 +6
–0 +7
Complement
• Negative number:
–0 +0
Bitwise complement of –1 1111 0000 +1
positive number –2 1110 0001 +2
1101 0010
– 0111 ≡ 710 –3 +3
1100 0011
– 1000 ≡ –710
– 4 1011 0100 + 4
1010 0101
–5 1001 0110 +5
–6 1000 0111 +6
–7 +7
1’s Complement
• Benefits:
– Simplifies arithmetic
– Only one zero!
1.6 Signed Binary Numbers
• To represent negative integers, we need a notation for
negative values.
• It is customary to represent the sign with a bit placed in
the leftmost position of the number since binary digits.
• The convention is to make the sign bit 0 for positive
and 1 for negative.
• Example:
Operation with 2’s complement
• Add 4 and -6
• Will use the 2’s complement of -6 or 1010
4 0100
-6 1010
1110
• And taking the 2’s complement of 1110 get
0001 + 1 = 0010
Complements
• Example 1.7
– Given the two binary numbers X = 1010100 and Y = 1000011,
perform the subtraction (a) X – Y ; and (b) Y − X, by using 2's
complement.
1010 0111
0011
2. + 6. - 0010
1110 1010
0101
3. + 7. - 0111
0111 1110
1010
4. + 8. - 0100
Subtraction example
Reference:
COMPUTER ORGANIZATION
AND ARCHITECTURE
DESIGNING FOR PERFORMANCE
NINTH EDITION
William Stallings
Problems from textbook
1.11 Perform the following division in binary: 111011 ÷ 101.
1.14 Obtain the 1’s and 2’s complements of the following binary
numbers:
(a) 00010000 (b) 00000000
(c) 11011010 (d) 10101010
(e) 10000101 (f) 11111111.
Problems from textbook
1.22 Convert decimal 6,514 to both BCD and ASCII codes. For ASCII, an even parity bit is to be
appended at the left.
1.23 Represent the unsigned decimal numbers 791 and 658 in BCD, and then show the steps
necessary to form their sum.
1.24 Formulate a weighted binary code for the decimal digits, using the following weights:
(a) * 6, 3, 1, 1
(b) 6, 4, 2, 1
• BCD addition
Binary Code
• Example:
– Consider the addition of 184 + 576 = 760 in BCD:
010 011
100 101
110 111
Binary Storage
• Registers
– A binary cell is a device that possesses two stable states and is capable of storing one of
the two states.
– A register is a group of binary cells. A register with n cells can store any discrete
quantity of information that contains n bits.
n cells 2n possible states
• A binary cell
– Two stable state
– Store one bit of information
– Examples: flip-flop circuits, ferrite cores, capacitor
• A register
– A group of binary cells
– AX in x86 CPU
• Register Transfer
– A transfer of the information stored in one register to another.
– One of the major operations in digital system.
– An example in next slides.
A Digital Computer Example
Memory
Control
CPU unit Datapath
z=x•y=xy z=x+y z = x = x’
x x x
y z y z z
Switching Circuits
AND OR
Binary Logic
• Logic gates
– Example of binary signals
3
Logic 1
2
Un-define
1
Logic 0
0
• Logic gates
– Graphic Symbols and Input-Output Signals for
Logic gates: