You are on page 1of 36

Binary System

Lecture - 01
Md. Zubair Alam

https://youtu.be/XTAsBQgxVGg
Numbers
• Decimal Number
7392 = 7 x 103 + 3 x 102 + 9 x 101 + 2 x 100
• In general decimal numbers are written as
a3a2a1a0.a-1a-2
= 103a3 + 102a2 + 101a1 + 100a0 + 10-1a-1 + 10-2a-2
• Decimal number system is of base, or
radix, 10 because it uses 10 digits and the
coefficients are multiplied by powers of 10.
Binary Number
• Binary system is a different number
system whose base (radix) is 2.
• It has only 2 coefficients: 0 and 1
• Coefficients are multiplied by power of 2.
11.112 = 1 x 21 + 1 x 20 + 1 x 2-1 + 1 x 2-2 = 3.7510
(110101)2 = 32 + 16 + 4 + 1 = (53)10
• In computer work:
210 = K(ilo), 220 = M(ega), 230 = G(iga), 240 = T(era)
• byte = 8 bits (≈ one keyboard character)
Binary Number
2n - 1 -> ‘n’ number of 1’s
Example:
• 23 - 1= 8 – 1= 7 -> 111
• 28 - 1= 256 – 1= 255 -> 11111111
Octal & Hexadecimal
• Octal
– Base (or radix) 8
– Total of 8 digits ( 0, 1, 2, 3, 4, 5, 6, 7 )
(127.4)8 = 1 x 82 + 2 x 81 + 7 x 80 + 4 x 8-1 = (87.5)10
• Hexadecimal
– Base (radix) 16
– Total 16 digits ( 0, 1,…, 8, 9, A, B, C, D, E, F )
(B65F)16 = 11 x 163 + 6 x 162 + 5 x 161 + 15 x 160
= (46,687)10
Numbers with different Bases
Decimal to Others
2 41
8 153
2 20 – 1
8 19 – 1
2 10 – 0
8 2–3
2 5–0
0–2 2318
2 2–1
2 1–0
101001 15310 = 2318
0–1
4110 = 1010012

Convert 77910 = ?16


0.6875 x 2 = 1.3750
16 779
0.3750 x 2 = 0.7500 16 48 – 11
0.7500 x 2 = 1.5000 16 3 – 0
0–3 30B16
0.5000 x 2 = 1.0000
77910 = 30B16
0.687510 = 0.10112
Binary vs Octal / Hexadecimal
• Octal ⬄ Binary (Group 3 digits)
(6153.7406)8 = 110 001 101 011 . 111 100 000 1102
1100000110.1012 = 001 100 000 110 . 101 = 1406.5
• Hexadecimal ⬄ Binary (Group 4 digits)
(2C6B.F2)16 = 0010 1100 0110 1011 . 1111 00102
1100000110.1012 = 0011 0000 0110 . 1010 = 306.A
• Octal ⬄ Hexadecimal
(C6B.F)16 = 1100 0110 1011 . 11112
= 110 001 101 011 .111 1002 = (6153.74)8
Add 0’s towards the left of decimal if necessary & add 0’s towards the
right if necessary.
Complements for Base 2
• 1’s complement
– 1’s complement of a binary number is formed
by changing 1’s to 0’s and 0’s to 1’s
• 1011000 -> 0100111
• 0100111 -> 1011000
• 2’s complement
– 2’s complement of a binary number is formed
by adding 1 to the 1’s complement value.
• 1011000 -> 0100111 + 1 = 0101000
• 0101000 -> 1010111 + 1 = 1011000
• 0110111 -> 1001000 + 1 = 1001001
Complements for Base 10
• 9’s complement
– 9’s complement of a decimal number is
formed by subtracting the digit from 9.
• 546700 -> 999999 – 546700 = 453299
• 012398 -> 999999 - 012398 = 987601
• 10’s complement
– 10’s complement of a decimal number is
formed by adding 1 to the 9’s complement
value. Number of digits is 6
• 546700 -> 453299 + 1 = 453300 = 106 - 546700
• 012398 -> 987601 + 1 = 987602 = 106 - 012398
Signed Binary Number
• First decide on the number of bits to represent
the signed binary number.
• MSB determines the sign of the binary number.
– 1 in MSB represent a negative number
– 0 in MSB represent a positive number
• 3 different methods to represent a signed binary
number
– Signed magnitude
– 1’s complement form
– 2’s complement form
• Stick with any one of the methods while
performing arithmetic operations, never mix and
match.
Signed Binary Number
• Signed magnitude
– MSB is used as sign bit and the rest of the bits represents the
magnitude.
– Used in ordinary arithmetic, but is awkward when employed in
computer arithmetic because of the separate handling of the
sign and the magnitude.
+0 and –0 have different representation

+8510 = 010101012 -8510 = 110101012

+010 = 000000002 -010 = 100000002


Signed Binary Number
• 1’s complement form
– Complement each bit to generate it.
– May be used for computer arithmetic.
+0 and –0 have different representation

+8510 = 010101012 -8510 = 101010102

+010 = 000000002 -010 = 111111112


Signed Binary Number
• 2’s complement
– Complement each bit and then add 1 to generate the 2’s
complement number.
– Used in most computers and digital systems
+0 and –0 have same representation
+8510 = 010101012 -8510 = 101010112

+010 = 000000002 -010 = 000000002


Table
Graphical View
Binary Addition
• Using 2’s complement method
– Represent the numbers in 2’s complement form and
add them, discarding the carry
– Make sure there is no overflow
• An addition overflows if the signs of the addends are the
same and the sign of the sum is different from the addend’s
sign.
• OR, an addition overflows if the carry in and carry out of
the sign bit are different

+6 0110 +3 0011 +5 0101


+ -3 + 1101 + +4 + 0100 + +6 + 0110
------- --------- ------- --------- ------- ---------
+3 10011 +7 0111 +11 1011 = -5

OVERFLOW
Binary Subtraction
• Using 2’s complement method
– Represent the subtrahend in 2’s complement
form and simply add to the minuend.
• A – B = A + (-B) = A + 2’s complement of B
– Make sure there is no overflow

+6 +6 0110 +3 0011 0011


- +3 + (-3) + 1101 - -4 - 1100 + 0100
------- ------- ---------- ------- ------- ----------
+3 +3 10011 +7 0111
1’s complement Addition/Subtraction
• Addition:
– Perform a standard binary addition; if there is a carry out of the sign
position, add 1 to the result
• Subtraction:
– Write the subtrahend in 1’s complement form and then add to the
minuend
• Overflow:
– Same rule as in 2’s complement i.e. overflow occurs if carry in and carry
out of MSB are different
Binary Multiplication
• Shift and add multiplication as in primary
school 

7 0111
x 3 0011
------- -------------------
21 0111
0111x
0000xx
0000xxx
-------------------
00010101
Binary Division
• Shift and subtract as in primary school again.
Binary Codes
• BCD
– Binary Coded Decimal
– Codes 0~9 using 4-bit unsigned binary representation 0000 thru 1001
(185)10 = ( 0001 1000 0101)BCD = (10111001)2
– Code words 1010 thru 1111 are not used
• BCD Addition
– Similar to adding 4-bit unsigned binary
– A correction must be made if result exceeds 1001
– Correction is made by adding 6 (i.e. 0110)

https://youtu.be/4Qc5aRKD9S4
BCD Addition

1010
which is
10 in
decimal >
1001 (9)

Add 0110
(6) to
correct
Binary Codes
• Gray Code
– Only 1-bit changes between
two neighboring numbers
– This prevents any unknown
state while transitioning.

Example: 1 1 1

1 0 0
Binary Codes
• BCD (8421)
• Excess 3-Code
• 2421
• 1-out-of-n code
• ASCII(American
Standard Code
for Information
Interchange)
Code
• 8421 and 2421 are weighted codes.
https://youtu.be/iMq_bAKhRv8
Decimal to Excess-3
• Convert 25 to Excess-3
Solution: Individual add 3 to each digit.
2 5
3 3
-------------------------
5 8
(0101 1000)
Excess-3
ASCII Code
• The ASCII code also contains 94 graphic
characters that can be printed and 34
nonprinting characters used for various control
functions.
• The graphic characters consist of the 26
uppercase letters (A through Z), the 26
lowercase letters (a through z), the 10 numerals
(0 through 9), and 32 special printable
characters, such as %, *, and $.
Error Detecting Code – Parity
• Parity bit is used to make the code to have even or odd
number of 1’s
• There are 2 types of parity
– Even
– Odd
• Parity bit is used for checking/correcting errors during
transmission of data between two computers.
Odd/Even Parity
Example
Type of bit parity error Failed transmission scenario

Alice wants to transmit: 1001


Alice computes parity bit value: 1^0^0^1 = 0
Alice adds parity bit and sends: 10010
...TRANSMISSION ERROR...
Even parityError in the second bit
Bob receives: 11010
Bob computes overall parity: 1^1^0^1^0 = 1
Bob reports incorrect transmission after
observing unexpected odd result
Binary Logic
• Deals with variables that take on two discrete values: 1
and 0
• Operation that assumes logical meaning
• Equivalent to Boolean algebra
• Related to digital logic circuits and binary signals.
• 3 basic logical operations:
– AND, OR, NOT
Binary Logic Operations
• AND
x . y = z or xy = z (x AND y is equal to z)
z = 1 if and only if x = 1 and y = 1; else z = 0
• OR
x + y = z (x OR y is equal to z)
z = 1 if x = 1 and/or y = 1; else z = 0
• NOT
x’ = z or = z (NOT x is equal to z)
x
z = 1 if x = 0; else z = 0
Binary Logic Operations
• Truth Table
– A truth table is a table of all possible combinations of the variables
showing the relation between the values that the variables may take and
the result of the operation.

AND OR NOT
x y x.y x y x+y x x’
0 0 0 0 0 0 0 1
0 1 0 0 1 1 1 0
1 0 0 1 0 1
1 1 1 1 1 1
Logic Gates
x z = x.y x z = x+y x z = x’
y y

2–input AND gate 2–input OR gate NOT gate or inverter

z = x.y

z = x+y

z = x’
XOR Gate
• If two inputs are same then output is 0 (low), else output
is 1 (high).
• C = A + B = AB+AB
HW
• 1.2, 1.3(d), 1.4, 1.6, 1.7, 1.8, 1.9(c,d,e), 1.12, 1.14(b,f,h),
1.16, 1.18(a,c), 1.23, 1.27, 1.29, 1.31~1.34

You might also like