You are on page 1of 76

Fundamentals & Ethics of

Information Systems
IS 201

Lecture 4

Binary Number System and Logic Gates

Lecture 4 – Binary System and Logic Gates


Learning Objectives
1. Know the different types of number systems
2. Describe positional number notation
3. Convert base 10 numbers into numbers of other bases and
vice versa
4. Describe the relationship between bases 2, 8, and 16
5. Identify the basic Boolean logic operations
6. Identify the basic gates and describe the behavior of each
using Boolean expressions and truth tables
7. Explain how a Boolean expression can be converted into
circuits

Lecture 4 – Binary System and Logic Gates


Chapter Overview
1. The Importance of Learning the Binary System
2. Number Systems
3. Conversions from the Decimal System to Other Systems
4. Converting Binary to Octal and Hexadecimal
5. Fixed-Point and Floating-Point Number Representations
6. Binary Arithmetic
7. Boolean Algebra
8. Logic Gates
9. Building Computer Circuits
10. Summary

Lecture 4 – Binary System and Logic Gates


1. The Importance of Learning the Binary
System**
n Modern computer systems do not represent numeric values
using the decimal system.
n Computers use a binary or two's complement numbering
system.
n To understand how the basic operations of the processor are
done.
n To be aware of the limitations of computer arithmetic, you
must understand how computers represent numbers.

Lecture 4 – Binary System and Logic Gates


2. Number Systems
n There are four number bases commonly used in
programming.
Name Base Digits Symbol
Binary 2 0,1 (N)2
Octal 8 0,1,2,3,4,5,6,7 (N)8
Decimal 10 0,1,2,3,4,5,6,7,8,9 (N)10
Hexadecimal 16 0,..,9,A,B,C,D,E,F (N)16

Lecture 4 – Binary System and Logic Gates


Decimal Number System
n The Decimal Number System uses base 10. It includes the
digits from 0 through 9. The weighted values for each position
is as follows:
104 103 102 101 100 10-1 10-2 10-3
10000 1000 100 10 1 .1 .01 .001

n When you see a number like "123", you don't think about the
value 123. Instead, you generate a mental image of how
many items this value represents. In reality, the number 123
represents:
1 * 102 + 2 * 101 + 3 * 100 =
1 * 100 + 2 * 10 + 3 * 1 =
100 + 20 + 3 =
123
Lecture 4 – Binary System and Logic Gates
Decimal Number System (Cont.)
n Each digit appearing to the left of the decimal point
represents a value between zero and nine times power of ten
represented by its position in the number.
n Digits appearing to the right of the decimal point represent a
value between zero and nine times an increasing negative
power of ten.
n For example, the value 725.194 is represented as follows:
7*102 + 2*101 + 5*100 + 1*10-1 + 9*10-2 + 4*10-3 =
7*100 + 2*10 + 5*1 + 1*0.1 + 9*0.01 + 4*0.001 =
700 + 20 + 5 + 0.1 + 0.09 + .0004 =
725.194

Lecture 4 – Binary System and Logic Gates


Binary Number System**
n The smallest "unit" of data on a binary computer is a single bit.
n Electronic components like transistors have a digital nature.
They can be either in an "on" state or an "off" state,
representing binary 1 and 0, respectively.
n The binary number system operates similarly to the decimal
system, but with a base of 2. In binary, only the digits 0 and 1
are used. 0,1
n The weighted values for each position is determined as follows:
27 26 25 24 23 22 21 20 2-1 2-2
128 64 32 16 8 4 2 1 .5 .25

Lecture 4 – Binary System and Logic Gates


Binary to Decimal
n Let’s convert the following two binary numbers to decimal
numbers: 10011 and 1101.01
10011 1*24 + 0*23 + 0*22 + 1*21 + 1*20 =
1*16 + 0*8 + 0*4 + 1*2 + 1*1 =
16 + 0 + 0 + 2 + 1 =
19

1101.01 1*23 + 1*22 + 0*21 + 1*20 + 0*2-1 + 1*2-2 =


1*8 + 1*4 + 0*2 + 1*1 + 0*.5 + 1*.25 =
8 + 4 + 0 + 1 + .25 =
13.25

Lecture 4 – Binary System and Logic Gates


Octal Number System
n The octal number system uses base 8 and includes only the
digits 0 through 7:
0,1,2,3,4,5,6,7
n The weighted values for each position is as follows:
85 84 83 82 81 80
32768 4096 512 64 8 1

Lecture 4 – Binary System and Logic Gates


Octal to Decimal
n Let’s convert the following two octal numbers to decimal
numbers: 736 and 670.32

736 7*82 + 3*81 + 6*80 =


7*64 + 3*8 + 6*1 =
448 + 24 + 6 = 478

670.32 6*82 + 7*81 + 0*80 + 3*8-1 + 2*8-2 =


6*64 + 7*8 + 0*1 + 3*.125 + 2*.015625 = 440.6875

Lecture 4 – Binary System and Logic Gates


Hexadecimal Number System
n The Hexadecimal Number System uses base 16 and includes
the digits 0 through 9 and the letters A, B, C, D, E, and F:

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E, and F

n The weighted values for each position is as follows:


163 162 161 160
4096 256 16 1

Lecture 4 – Binary System and Logic Gates


Hex to Decimal
n To convert from Hex to Decimal, multiply each hex digit by its
weight and add the results.

0AFB2 A*163 + F*162 + B*161 + 2*160 =


10*4096 + 15*256 + 11*16 + 2*1 =
40960 + 3840 + 176 + 2 =
44978

Lecture 4 – Binary System and Logic Gates


3. Conversion of Decimal Numbers
n Decimal to Binary Conversion
n Decimal to Octal conversion
n Decimal to Hexadecimal system

Lecture 4 – Binary System and Logic Gates


Decimal to Binary
n This method consists of two steps:
n Step 1
n Dividing the integer part by 2 until its value is 0 and to keep the
remainder R at each division.
n Step 2
n Concatenate the remainders starting by the bottom-up

Lecture 4 – Binary System and Logic Gates


Decimal to Binary (Cont.)
n Converting the decimal number 18 into the binary system.
Number/Base Integer Part Remainder Remark
18 /2 9 0 18 = 2 * 9 + 0
9 /2 4 1 9=2*4 + 1
4 /2 2 0 4=2*2 + 0
2 /2 1 0 2=2*1 + 0
1 /2 0 1 1=2*0 + 1

n Thus, 1810 = 100102

Lecture 4 – Binary System and Logic Gates


Decimal to Octal
n The same method is applied in this case except that we will
perform successive divisions by 8
n Example: Translating the decimal number 18 into the octal
system. Base is then 8
Number/Base Integer Part Remainder Remark
18 /8 2 2 18 = 8 * 2 + 2
2 /8 0 2 2=8*0 + 2

n Thus, 1810 = 228

Lecture 4 – Binary System and Logic Gates


Decimal to Hexadecimal
n The same method is applied in this case except that we will
perform successive divisions by 16
n Example: Translating the decimal number 18 into the
hexadecimal system. Base is then 16
Number/Base Integer Part Remainder Remark
18 /16 1 2 18 = 16 * 1 + 2
1 /16 0 1 1 = 16 * 0 + 1

n Thus, 1810 = 1216

Lecture 4 – Binary System and Logic Gates


4. Conversion of Binary Numbers**
n A major problem with the binary system is the large
number of digits needed to represent even small values.
n To represent 20210, eight binary digits are needed,
compared to only three in the decimal system.
n When dealing with large numeric values, binary numbers
quickly become unmanageable.
n The hexadecimal (base 16) numbering system solves this
issue with two key features:
n Compact representation.
n Simple conversion between hex and binary, and vice versa.

Lecture 4 – Binary System and Logic Gates


Uses of the Hexadecimal System**
n Color representation
n 165D31 :‫اﻟﻠون اﻻﺧﺿر ﻓﻲ اﻟﻌﻠم اﻟﺳﻌودي ﯾﻣﻛن ﺗﻣﺛﯾﻠﮫ ﻛﺎﻟﺗﺎﻟﻲ‬
Red:16, Green:5D, Blue:31
n https://www.color-hex.com/
n MAC (physical) addresses
n 00:1A:2B:3C:4D:5E
n Character encoding standards
n "IS201" equals 49 53 32 30 31 in UTF-8
n URL encoding
n "%20" in URLs signifies the space character in UTF-8

Lecture 4 – Binary System and Logic Gates


Converting Binary Numbers

1. Converting Binary to Octal


2. Converting Binary to Hexadecimal

Lecture 4 – Binary System and Logic Gates


Binary to Octal
n Convert 10101011 ! into octal
1. First, group the binary digits into sets of three from right to left
10 101 011
2. Then, for each group, multiply each digit with 2x where x is
incremented from 0 to 2 from right to left
10 101 011
21 20 22 21 20 22 21 20
3. Finally, sum the numbers for each group
2 5 3
n 10101011 is 253 in base 8

Lecture 4 – Binary System and Logic Gates


17
Octal to Binary
n Convert 71" into binary
n Transform each octal digit into a 3-digit binary number, starting
from the right.
7 1
111 001
n 71" is 111001!

Lecture 4 – Binary System and Logic Gates


17
Binary to Hexadecimal
n Convert 10101011 ! into hexadecimal
1. First, group the binary digits into sets of four from right to left
1010 1011
2. Then, for each group, multiply each digit with 2x where x is
incremented from 0 to 3 from right to left
1010 1011
23 22 21 20 23 22 21 20
3. Finally, sum the numbers for each group

n Therefore, 10101011 ! is AB#$

Lecture 4 – Binary System and Logic Gates


18
Hexadecimal to Binary
n Convert 𝐴1!" into binary
n Transform each hex digit into a 4-digit binary number, starting
from the right. Remember that A=10
A 1
1010 0001
n 𝐴1!" is 10100001#

Lecture 4 – Binary System and Logic Gates


17
5. Fixed-Point and Floating-Point
Number Representations**
n Fixed-point number representation
n Represents numbers with a fixed number of digits after the decimal
point.
n Example: 1010.1000 is a fixed-point number with 4 integer bits and 4
fractional bit.
n Disadvantages: Limited range and precision compared to floating-
point representation.

Lecture 4 – Binary System and Logic Gates


5. Fixed-Point and Floating-Point
Number Representations**
n Floating-point number representation
n Represents numbers as a scientific notation (as in 1.010101001x 2^6),
allowing a variable number of digits before and after the decimal point.
n It consists of three parts: sign bit, exponent, and fraction.

n Example: 85.125
n 8510 = 10101012 and 0.12510 = 0012

n 85.12510 = 1010101.0012 = 1.010101001 x 2^6

n Fraction= 010101001, Exponent = 6, Sign = 0


n The representation involves more details, but here we're just providing
a basic explanation.

Lecture 4 – Binary System and Logic Gates


5. Fixed-Point and Floating-Point
Number Representations
n Let's compare the range expansion using 32 bits for both
fixed-point and floating-point representations:
n For the fixed-point, if we allocate 16 bits for the integer part and 16 bits
for the fractional part, the range of representable numbers would be
from −32,768.9999847412109375 to 32,767.9999847412109375
n The range of numbers in floating-point (using the IEEE 754 single-
precision format) is approximately from 1.175 × 10!"# to 3.403 × 10"#

Lecture 4 – Binary System and Logic Gates


Limitations of Computer Arithmetic⁺
n Binary representation encounters difficulties with certain
non-integer values like 0.1#%, 0.3#%, and 0.55#%
n They become non-terminating in binary
n Exercise: Using the following tool
https://www.exploringbinary.com/binary-converter/, compare the
conversion into binary of 3.5$% and 3.55$% .
n 3.55$% is more challenging to represent in binary

n Rounding is often employed to deal with these


challenges. However, it introduces errors in certain cases.
n Exercise: In python, try 0.2+0.1
n Rounding off errors in Java:
https://www.geeksforgeeks.org/rounding-off-errors-java/

Lecture 4 – Binary System and Logic Gates


Limitations of Computer Arithmetic⁺
n Highly recommended video:
https://www.youtube.com/watch?v=PZRI1IfStY0

Lecture 4 – Binary System and Logic Gates


5. Binary Arithmetic

1. Binary Addition
2. Binary Subtraction

Lecture 4 – Binary System and Logic Gates


Addition
n In the binary system, there are four addition cases taking into
account the digits 0 and 1 and the possible carry:

Operation result carry

0+0 0 0
0+1 1 0
1+1 0 1
1+1+1 1 1

Lecture 4 – Binary System and Logic Gates


Addition (Cont.)
n Perform the addition of the following binary numbers:
110010 and 100111

Carry values
11
110010
+
100111
1011001
Lecture 4 – Binary System and Logic Gates
Exercises
1. Convert the following numbers into decimal numbers
n (01)2, (111)2, (10011.11)2, (11010.101)2
2. Convert the following numbers into octal/hex
n (01)2, (101111)2, (10011)2, (11011010)2
3. Convert the following numbers into binary numbers
n (0)10, (10)10, (56)10, (169)10
n (135)8, (021)8, (703)8
n (135)16, (0A1)16, (0E)16
4. Perform the following binary operations
n 11 + 11, 1101 + 111, 11111 + 100011

Lecture 4 – Binary System and Logic Gates


Subtraction
n Subtraction in an ALU is typically performed using a
combination of addition and complement operations.
n Complement operations are the method used to represent negative
numbers.
n Consider the subtraction 7-4. This can be reformulated as
7+(-4), where the negative term is represented using two's
complement notation.

Lecture 4 – Binary System and Logic Gates


Negative Numbers in Binary

n Signed magnitude
n One’s complement
n Two’s complement

Lecture 4 – Binary System and Logic Gates


Signed Magnitude
n In signed magnitude representation, the leftmost bit is the
sign bit (0 for positive, 1 for negative).
n The remaining bits represent the magnitude of the number.
n Example:
n 7 in signed magnitude: 0111
n -7 in signed magnitude: 1111
n Limitation: Cannot perform arithmetic operations directly
n Try 7+(-3)
n The immediate result is incorrect

Lecture 4 – Binary System and Logic Gates


One’s Complement
n In one's complement, negative numbers are represented by
inverting all the bits of the corresponding positive number.
n Example:
n 5 in one's complement (8-bit): 00000101
n −5 in one's complement (8-bit): 11111010 (Inverted bits of +5)
n Limitation: Cannot perform arithmetic operations directly
n Try 7+(-3)
n The immediate result is incorrect

Lecture 4 – Binary System and Logic Gates


Two’s Complement
n In two's complement, negative numbers are represented by:
n Inverting all the bits of the corresponding positive number.
n Adding 1 to the result.
n Example:
n 7 in two's complement (4-bit): 0111
n −7 in two's complement (4-bit): 1001 (Invert 0111 then add 1)
n Two's complement performs arithmetic operations accurately.
n Try 7+(-3)

Lecture 4 – Binary System and Logic Gates


Character Encoding**
n ASCII
n Developed in the early days of computing.
n Uses 7 bits to represent 128 characters, including letters, numbers,
punctuation, and control characters.
n Extended ASCII uses 8 bits, providing additional characters.
n In ASCII, 'A' is represented as 01000001.
n UTF-8: A Variable-Length Encoding
n UTF-8 is a widely used encoding that adapts to the character being
represented.
n One to four bytes are used to represent characters, making it efficient
and backward compatible with ASCII.
n In UTF-8, '€' (Euro sign) is represented as 11100010 10000010
10101100.
n In UTF-8, ' ' (Space) is represented as 00100000
Lecture 4 – Binary System and Logic Gates
Optional Resources⁺
n Characters, Symbols and the Unicode Miracle
n https://www.youtube.com/watch?v=MijmeoH9LT4
n https://symbl.cc/en/

Lecture 4 – Binary System and Logic Gates


7. Boolean Algebra
n Why computers use the binary system?
1. Electronic components like transistors have a digital nature. They can be
either in an "on" state or an "off" state, representing binary 1 and 0,
respectively.
2. An entire branch of mathematics already existed that dealt exclusively
with true and false values.

Lecture 4 – Binary System and Logic Gates


Boolean Algebra Components
n The set of Boolean values {F,T}
n Boolean variables a, b, …∈ {F,T}
n Boolean operations {AND, OR, NOT}
n Boolean expressions
n Boolean functions

Lecture 4 – Binary System and Logic Gates


Boolean Operations
n a AND b
n True only when a is true and b is true
n a OR b
n True when a is true, b is true, or both are true
n NOT a
n True when a is false and vice versa

Lecture 4 – Binary System and Logic Gates


Boolean Expressions
n Constructed by combining together Boolean operations and
variables
n Example: (a AND b) AND c

a b c a AND b (a AND b) AND c


F F F F F
F F T F F
F T F F F
F T T F F
T F F F F
T F T F F
T T F T F
T T T T T

Lecture 4 – Binary System and Logic Gates


8. Logic Gates
n Gates are hardware devices built from transistors to mimic
Boolean Operations
n Transistors are made of semiconductor materials
n Types of materials based on their conductivity:
n Conductors: copper and aluminum
n Insulators: rubber, glass, and plastic
n Semiconductors: silicon and germanium
n What is A Semiconductor:
https://www.youtube.com/watch?v=gUmDVe6C-BU (0:00 to 1:26)

Lecture 4 – Binary System and Logic Gates


AND Gate

Source: The Crash Course Computer Science


Lecture 4 – Binary System and Logic Gates
AND Gate

Source: The Crash Course Computer Science


Lecture 4 – Binary System and Logic Gates
AND Gate

Source: The Crash Course Computer Science


Lecture 4 – Binary System and Logic Gates
OR Gate

Source: The Crash Course Computer Science


Lecture 4 – Binary System and Logic Gates
OR Gate

Source: The Crash Course Computer Science


Lecture 4 – Binary System and Logic Gates
OR Gate

Source: The Crash Course Computer Science


Lecture 4 – Binary System and Logic Gates
OR Gate

Source: The Crash Course Computer Science


Lecture 4 – Binary System and Logic Gates
Logic Gates (cont.)
n Boolean values (F,T) ----- signal value (0,1)
n Boolean operations ----- logic gates
n Boolean function ------ logic circuit

Lecture 4 – Binary System and Logic Gates


Three Basic Gates

Basic Gates

Symbols

Truth Tables

The Three Basic Gates, Their Symbols and Truth Tables

Lecture 4 – Binary System and Logic Gates


9. Building Computer Circuits
n A circuit is a collection of logic gates
n Transforms a set of binary inputs into a set of binary outputs
n Values of the outputs depend only on the current values of the inputs

Diagram of a Typical Computer Circuit

Lecture 4 – Binary System and Logic Gates


The Design Process of
Compare-for-Equality Circuit
n Problem specification
n Define the logical function and specify the number of inputs and
outputs.
n Truth table generation
n The table lists all possible combinations of input values and their
corresponding output values.
n Logic expression derivation
n Simplification of logic expression
n Logic circuit design

Lecture 4 – Binary System and Logic Gates


CE: Problem Specification
n Compare-for-equality compares two binary numbers for
equality.
n For example, let A= 1001 and B= 1010, is A equals B?
n Built by combining together 1-bit comparison circuits (1-CE)
n A circuit for the first digit, and another circuit for the second digit, etc
n A and B are equal if corresponding bits are equal.

Lecture 4 – Binary System and Logic Gates


1-CE: Truth Table Generation

a b F
0 0 1 Truth table
captures every
0 1 0 input/output
1 0 0 possible for circuit

1 1 1

Lecture 4 – Binary System and Logic Gates


1-CE: Logic Expression Derivation

1. For each line with output 1 in the truth table, build a product
term using AND and NOT
2. Combine together all product terms with ORs

a b F
0 0 1
0 1 0
1 0 0
1 1 1

Lecture 4 – Binary System and Logic Gates


1-CE: Logic Expression Derivation

1. For each line with output 1 in the truth table, build a product
term using AND and NOT
2. Combine together all product terms with ORs

a b F
0 0 1
Writing a Logic0Expression
1 From
0 a Truth Table
https://www.youtube.com/watch?v=uZel7wLztM0
1 0 0
1 1 1

Lecture 4 – Binary System and Logic Gates


1-CE: Simplification of Logic Expression
n This expression can be minimized/simplified, but
we won't address that process here.
n Examples of minimization can be found in Slide 71 and Slide
75

Lecture 4 – Binary System and Logic Gates


1-CE: Logic Circuit Design
n From this expression , we design the circuit

Lecture 4 – Binary System and Logic Gates


4-CE Circuit

a0 A and B are equal


b0 1-CE if corresponding
bits are equal
a1

b1
1-CE
AND
F
gate
a2
1-CE
b2

a3

b2
1-CE

Lecture 4 – Binary System and Logic Gates


Exercise 1
n Find the output of the following circuit

x
y
y

Lecture 4 – Binary System and Logic Gates


Exercise 1: Solution
n Find the output of the following circuit

x 𝒙+𝒚
y (𝒙 + 𝒚)$
𝒚
$
𝒚
y
n .
Answer: 𝒙 + 𝒚 - 𝒚

Lecture 4 – Binary System and Logic Gates


Exercise 2
n Find the output of the following circuit

x
y

Lecture 4 – Binary System and Logic Gates


Exercise 2: Solution
n Find the output of the following circuit

$
𝒙
x $'𝒚
𝒙 $ $'𝒚
𝒙 $
$
𝒚
y
n .-𝒚
Answer: 𝒙 . =𝒙+𝒚

Lecture 4 – Binary System and Logic Gates


Exercise 3
n Design the circuits for the following Boolean algebraic
expression: 𝑥̅ + 𝑦
n Solution:
$
𝒙
x $+𝒚
𝒙
y

Lecture 4 – Binary System and Logic Gates


Exercise 4
n Design the circuits for the following Boolean algebraic
expressions: (𝑥 + 𝑦) 𝑥
n Solution:

x 𝒙+𝒚
𝒙+𝒚
𝒙+𝒚 𝒙
y

Lecture 4 – Binary System and Logic Gates


The Half-Adder
n Sum = 𝑥̅ - 𝑦 + 𝑥 - 𝑦5 x y Carry Sum
= 𝑥 + 𝑦 - (𝑥̅ + 𝑦)
5 0 0 0 0
= 𝑥 + 𝑦 - (𝑥𝑦) 0 1 0 1
n Carry = 𝑥 - 𝑦 1 0 0 1
1 1 1 0

x
y Sum
Carry
Lecture 4 – Binary System and Logic Gates
Examples of Essential Circuits in Digital
Logic Design
n Performing arithmetic operations
n Half-adder and full-adder
n Executing logic operations
n Compare for equality
n Providing memory capabilities

Source: The Crash Course Computer Science

Lecture 4 – Binary System and Logic Gates


Circuit Equivalence

(AB + AC)

Lecture 4 – Binary System and Logic Gates


Circuit Equivalence

(AB + AC)

Both circuits produce the exact same output


for each input value combination, but one is
simpler than the other.

Lecture 4 – Binary System and Logic Gates


Minimization
n Boolean algebra allows us to apply provable mathematical
principles, like the properties of Boolean algebra listed
below, to simplify the design of logic circuits.

n In the previous slide, 𝐴 ⋅ 𝐵 + 𝐶 is simpler than (𝐴 ⋅ 𝐵) + (𝐴 ⋅ 𝐶)


n 𝐴 ⋅ 𝐵 + 𝐶 uses only two gates.
n (𝐴 ⋅ 𝐵) + (𝐴 ⋅ 𝐶) uses three gates.

Lecture 4 – Binary System and Logic Gates


10. Summary
n Number Systems: Decimal, Binary, Octal, Hexadecimal
n Convert Decimal to other number systems and vice versa
n Binary arithmetic
n Boolean logic and basic Boolean operations
n Gates and Boolean logic

Lecture 4 – Binary System and Logic Gates

You might also like