0% found this document useful (0 votes)
21 views

Machine_structure_Chapter 2

The document outlines the course 'Machine Structure I', focusing on numeral systems, aimed at first-year Bachelor’s students in Computer Science or Electronics. It covers various numeral systems including Decimal, Binary, Octal, and Hexadecimal, along with their conversions and basic arithmetic operations. The course is structured into chapters that include an introduction to numeral systems, their conversions, and arithmetic operations, with specific objectives for student comprehension by the end of the chapter.

Uploaded by

amazouzmehdi118
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Machine_structure_Chapter 2

The document outlines the course 'Machine Structure I', focusing on numeral systems, aimed at first-year Bachelor’s students in Computer Science or Electronics. It covers various numeral systems including Decimal, Binary, Octal, and Hexadecimal, along with their conversions and basic arithmetic operations. The course is structured into chapters that include an introduction to numeral systems, their conversions, and arithmetic operations, with specific objectives for student comprehension by the end of the chapter.

Uploaded by

amazouzmehdi118
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Machine Structure I

Chapter II: Numeral systems

Presented by:
Dr. BEN SI SAID KARIM
Grade: Associate Professor
[email protected] Department: Computer Science
Faculty: Faculty of Sciences
University: Algiers 1

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 1


Course overview

Machine Structure I: Represents one of the fundamental pillars that any student aspiring to delve
into computer science must master. This module provides a crucial foundation for understanding the
functioning of computers and digital systems.
Target Audience: 1st year Bachelor’s students, in Computer Science or eletronics
Course : Fundamental unit
Credits : 05
Coefficient : 03
Semester : 01 / 14 weeks
Sessions duration: 1h 30 per week:

Dr. BEN SI SAID Karim - Ped@tic 2024 – Session Janvier – Groupe 97 2


Course outlines

➢ Chap 1 Introduction (Computer and machine language)


➢ Chap-2 Numbering system
Decimal, Binary, Octal and Hexadecimal and conversion
Basic operations in binary (Addition, Subtraction, Multiplication and Division)

➢ Chap-3 Coding & Number Representation


Binary Coding (Pure binary, Gray code, BCD, Excess-3 code.
Character Representation EBCDIC code, ASCII code, UTF code.
Number Representation (Integers, Fractional Numbers)

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 3


Unit Outlines

➢ Chap-4 Boolean Algebra


• Definition and Axioms of Boolean Algebra
• Basic Operators and schematic representation (AND, OR, NOT, NAND, XOR,…)
• Truth table
• Logical Expressions and Functions.
• Algebraic Representation of a Function in the First and Second Normal Forms.
• Expression of a Logical Function using Only NAND or NOR Gates.
• Logic Diagram of a Function.
• Simplification of a Logical Function
(Algebraic method, Karnaugh maps,)

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 4


Enroll in google classroom

Course code:

rgps3on

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 5


Chapter objectives

By the end of this chapter :

✓ Understand the basics of numeral systems (Decimal, Binary, Octal and Hexadecimal)
✓ Apply different conversion between numbers from a base to another
✓ Perform the basic arithmetic operations in binary for integers and fractional numbers
(Addition, Subtraction, Multiplication and Division)

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 6


Chapter II Outlines
I. Introduction
II. Numeral system
• Decimal
• Binary
• Hexadecimal
• Octal
III. Conversion between bases
• Decimal – base B
• Base B – Decimal
• Binary- hexadecimal – Binary
• Binary- Octal – Binary
IV. Arithmetic operations
• Addition
• Subtraction
• Division
• Multiplication

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 7


Chapter- II : Introduction

• Throughout human history, various civilizations and


cultures have developed unique ways to represent
and convey numbers.
• Romans: uses 7 symbols I, V, X, L, C, D, M
System based on addiction or subtraction of numbers from
each other depending on the position.
Example
• CD = 500 – 100 = 400
• XLVII = 50 – 10 + 5 + 1 + 1 = 47
47: We take the biggest value (L = 50), we subtract
(X=10 (on left)), then we add what is on its right side
• MCMXCV = 1000 +(1000 - 100)+(100-10) + 5 = 1995
= M + CM + XC + V

➔ Difficult Puzzle Copyright © Karim Ben Si Said L1 – INFO -2024/2025 8


Chapter- II : Numeral system --> Decimal

• The counting system of nowadays known as the


Hindu-Arabic numeral system is called Decimal.
• Based on 10 symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The
concatenation of these symbols gives numbers.
• From right to left, the 1st digit represents the units,
the 2nd is the tens, the 3rd represents the hundreds
and so on.
• The position of each digit in a number is crucial, it
represents a multiplier of the power of the base 10.

Example
140,360: one hundred forty thousands, three hundred sixty
368: three hundred sixty-eight
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 9
Chapter- II : Numeral system --> Decimal

Digits and power


• Each column in a decimal number represents a power of 10 starting from the right
with 100 as the Least Significant Digit LSD, to the left with the Most Significant Digit
MSD.
• The fractional digits have a negative power: 10-1 ,10-2 ,10-3, etc.

Integer Fractional
Example part part

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 10


Chapter- II : Numeral system --> Decimal

Polynomial form
• Every decimal number can be written in the polynomial form.
• The overall value of the number is obtained by summing the values of each digit
multiplied by the appropriate powers of the decimal base 10.
Example
436 = 400 + 30 + 6 = 4 x 100 + 3 x 10 + 6 x 1 = 4 x 102 + 3 x 101 + 6 x 100
128.71 = 1x102 + 2 x 101 + 8 x 100 + 7 x 10-1 + 1 x 10-2
n−1

NB = ai B i
i= −p

Where ai are the digits of the number, Bi the power of the digit (i), and n, p are the number of digits
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 11
Chapter- II : Numeral system --> Decimal

Notes
• A numbering system consists of specific rules and symbols that enable the
representation of quantitative information. It is based on 3 aspects:

• The base : refers to a value that dictate the weight (power) of digits. (example
with the previous number (128.71)10 in decimal base (10)
• A set of symbols and/or characters used to represent a quantity
(example 0,1,2,3,4,5,6,7,8,9)
• Rules. For example: rule1 the number of characters should be less than the base
(in decimal base we have 10 characters => 0 → 9 < 10). Rule2 : when writing, the
position of the digits (0123. 0153: position of 0 is not significant in 0123 but
important in .0153)
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 12
Chapter- II : Numeral system --> Other numeral systems

Other numeral systems


Name Digits, Symbols Number Notation
Base
• Thus, as in decimal base, we can (characters or numbers) example
define a multitude of numbering 16 Hexadecimal 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F (A5)16 0xA5

systems. Using known 10 Decimal 0,1,2,3,4,5,6,7,8,9 (125)10 125

characters numbers and/or 9 nonary 0,1,2,3,4,5,6,7,8 (857)9

letters. 8 Octal 0,1,2,3,4,5,6,7 (73)8 073


7 septenary 0,1,2,3,4,5,6 (64)7
• In programming, distinct notations
6 senary 0,1,2,3,4,5 (15)6
are utilized to enable the
5 quinary 0,1,2,3,4 (243)5
computer to differentiate between
4 Quaternary 0,1,2,3 (32)4
numbers in different base
3 Ternary 0,1,2 (12)3
Example
2 Binary 0,1 (1101)2 0b1101
(1110)10 ≠ (1110)2
Notation: 1110 for decimal and 0b1110 for binary
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 13
Chapter- II : Numeral system --> Binary, Hexadecimal and octal

Commonly used numeral systems


• Decimal is the basic system used by humans

• There are three common numeral systems used


essentially by machines:
✓ Hexadecimal (base 16)
✓ Octal (base 8)
✓ Binary (base 2).

• To specify the base in which a number is written, we enclose the


number in parentheses and denote the base as subscript
Example (436)10 ,(37)8 ,(10101011)2 ,(73BC)16 (312)2 Wrong !
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 14
Chapter- II : Numeral system --> Binary, Hexadecimal and octal

Power and fractional numbers


• As in decimal, the fractional part of a
number has a negative power values.
• The power of a digit depends on the base and its
position (e.g. 20, 83, 162 ).
• In binary a digit is a called a bit
The Most Significant Bit MSB
The Least Significant Bit LSB
• A concatenation of 8 bits forms a Byte which is
the fundamental unit of storage in computing

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 15


Chapter- II : Numeral system --> Binary, Hexadecimal and octal

Exercise
• Write the power of each digit for the following numbers:
(1101.101)2, (5AD.0C)16, (13.21)4, (734.5)8

23 20 2-1 40 4-1 80 8-1


160 16-1 81
Power 21 2-2 161 16-2 41 4-2
22 2-3 82
162

1101. 101 5AD.0C 13.21 735. 5

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 16


Chapter- II : Numeral system --> Binary, Hexadecimal and octal
Dec (10)s Oct (8) Hex(16) Bin (2)
Exercise 0 0 0 00000
1 1 1 00001
Fill in the following table: 2 2 2 00010
3 3 3 00011
4 4 4 00100
• Octal: We count 0,1,2,3,4,5,6,7 and then put a 0 in the first 5 5 5 00101
column and add a new left column, starting at 1 again (10). 6 6 6 00110
Then we count 0-7 in the first column again 7 7 7 00111
8 10 8 01000
• :
Hexadecimal We count 0,1,2,3,....,9,A,B,C,D,E,F and then 9 11 9 01001
10 12 A 01010
put a 0 in the first column and add a new left column, 11 13 B 01011
starting at 1 again (10). Then we count 0-F in the first 12 14 C 01100
column again 13 15 D 01101
14 16 E 01110
• Binary: We count 0,1 and then put a 0 in the first column 15 17 F 01111
16 20 10 10000
and add a new left column, starting at 1 again (10). Then we
17 21 11 10001
count 0-1 in the first column again 18 22 12 10010
19 23 13 10011
20 24 14 10100
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 17
Chapter- II : Numeral system --> Binary, Hexadecimal and octal

Counting possibilities
• In a given base B, the number of counting possibilities P is function of the base B and the
number of digits D
P = BD
Examples
• In decimal with 2 digits, we can write 102 = 100 values: 0→(99)10
• In decimal with 3 digits, we can write 103 = 1000 values 0→(999)10

• In Hexadecimal with 3 digits, we can write 163 = 4096 values 0→(FFF)16

• In Octal with 3 digits, we can write 83 = 512 values 0→(777)8

• In binary with 3 digits, we can write 23 = 8 values 0→(111)2


• In binary with 5 digits, we can write 25 = 32 values 0→(11111)2

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 18


Chapter- II : Numeral system --> Binary, Hexadecimal and octal

Exercise
• How much RAM memory we can handle with a 32-bit system ?
232 = 4,294,967,296 = 4 Gigabytes (GByte)

• 1 nibble = 4 bits
• 1 Byte = 1 octet = 8 bits
• 1 byte (8 bits) can represent a character (e.g., a letter, number, or symbol).
• 1 kilobyte (KB) is approximately 1,024 bytes (or 8,192 bits).
• 1 megabyte (MB) is approximately 1,024 KB (or 8,388,608 bits).
• 1 gigabyte (GB) is approximately 1,024 MB (or 8,589,934,592 bits).

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 19


Chapter- II : Conversion between bases
1. From base B to decimal
To convert a number from a given base to decimal, we use the polynomial formula:

Examples
• (A5)16 = A x 161 + 5 x 160 = 10 x 16 + 5 x 1 = 165
2
• (73.2)8 = 7x81 + 3x80 + 2x8-1 = 56 + 3 + 8 = 59.25
2 2
• (32.22)4 = 3x41 + 2x40+ 2x4-1 + 2x4-2 = 12+2+ 4 ​+ 16 = 14.625

• (12.01)3 = 1x31+ 2x30 + 0x3-1 + 1x3-2 = 5.111


1 1
• (101.011)2 = 1x22 + 0x21+ 1x20 + 0x2-1 + 1x2-2 + 1x2-3 = 4+0+1+0+ + 4 ​+ 8 = 5.375

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 20


Chapter- II : Conversion between bases

2. From decimal to base B


Example
The conversion of a number N from decimal to any base B, (75)10= (1023)4
is performed with the following steps:
• Divide the decimal number N by the base B and write Decimal
Base
down the quotient Q and the remainder R. Number to
75 4
convert
• Repeat the division of the quotient by the base B then 3 18 4 Quotient
write down the new quotient and the new remainder. Reminder
Until the quotient becomes zero
2 4 4
0 1 4
1023
• Write the remainders from each division in reverse 1 0
order (from the last remainder to the first).

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 21


Chapter- II : Conversion between bases

2. From decimal to base B


Examples
(123)10= (1111011)2
(123)10= (173)8
(13)10= (1101)2
(123)10= (443)5
(51)10= (110011)2

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 22


Chapter- II : Conversion between bases

3. Decimal to Binary → Fractional numbers


• We use the approach of successive multiplication, to
Example
convert the fractional part:
Convert 0.25 to binary

1. Multiply the fractional part by the base (2)


0.25 x 2 = 0.5
2. Multiply the resulting fractional part (example 0.5) by the base 0.5 x 2 = 1.0
and continue the process until: - the desired precision is
achieved, the fractional part becomes zero, or we notice a 0.25 = (0.01)2
repeating pattern.
3. Extract the integer part from the result of each multiplication

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 23


Chapter- II : Conversion between bases

3. Decimal to Binary → Fractional numbers


• Example
Convert 13.74 to binary with 5 digits after the radix point

1. Integer part: 2. Fractional part


Convert 0.74 to binary

(0.74)10 = (0.10111)2
0.74 x 2 = 1.48
0.48 x 2 = 0.96
0.96 x 2 = 1.92 → 13.74 = (1101. 10111)2
0.92 x 2 = 1.84
1101
0.84 x 2 = 1.68
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 24
Chapter- II : Conversion between bases
❖ Conversion Decimal- base B - decimal
• The conversion from a base B to decimal, or from decimal to another base can be illustrated using a
balance taking the decimal number in one pan, and the powers and weights of the bases in the other.
• In the following example, we have 7 digits of base 2 (binary) with the weights:
➢ 20 = 1, 21 = 2, 22 = 4, 23= 8, and 24 = 16, for the integer part
➢ 2 digits with weights 2-1 = 0.5, and 2-2 = 0.25 for the fractional part.
• To make the number 5.75 in binary, we take the bits representing the power of 22 = 4, 20 = 1 for the Integer
part and 2-1 = 0.5, and 2-2 = 0.25 for the fractional.
• In binary, we have only one piece of each weight (we can use it: (1), or not: (0))

23 20 2-2
5.75 24 21
0.5

0.5 0.25 2-1


0.25

16 8 4 2 1 22

24 23 22 21 20 2−1 2 −2 5= 00101.11
Decimal Binary
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 25
Chapter- II : Conversion between bases
❖ Conversion Decimal- base B - decimal
• In binary, we have only one piece of each weight (we can use it: (1), or not: (0))
• In other bases there are more than one sample of each weight (7 pieces in octal, and 15 in hexadecimal)
Example 1: To form (10)10 in octal, we use two weights of 80 = 1, and one weight 81 = 8
Example 1: To form (138)10 in octal, we use two weights of 80 = 1, one weight 81 = 8 and two weights 82 = 64

80
10 81

10 =(12)8
Decimal Octal 82 81 80
80
81 64
82 8 1
138
138 =(212)8
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 26
Decimal Octal
Chapter- II : Conversion between bases

4. Conversion from B1 to Base B2


• To convert a number from one base (B1) to another base (B2), a commonly used
approach involves converting the number to decimal (base 10) as an intermediate
step.
Example (22)5 = ( ? ) 3 10
(22)5 = 2x51 + 2x50 = (12)10

12 3 (12)10 = (110)3
0 4 3 ?
B1 B2
1 1 3
1 0
→ (22)5 = (12)10 = (110)3
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 27
Chapter- II : Conversion between bases

4. Binary – hex
Hex(16) Bin (2)
To convert from binary to hexadecimal, we group every 4 bits in the binary 0 0000
representation and convert each group to its respective hexadecimal digit 1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
Example 9 1001
A 1010
11101.010101 = 0001 1101. 0101 0100 = 0x1D.54 B 1011
C 1100
111111.11001 = 0011 1111. 1100 1000 = 0x3F.C8 D 1101
E 1110
F 1111

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 28


Chapter- II : Conversion between bases
4. Hex –Binary
Hex(16) Bin (2)
0 0000
With the same way, every hexadecimal digit can be converted directly to 4
1 0001
bits binary number. 2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
Example 9 1001
A 1010
0x1D.5 = 1 1101.0101 B 1011
C 1100
0x3FC.8 = 11 1111 1100.1000 = 11 1111 1100.1 D 1101
E 1110
0xB.1 = 1011. 0001 F 1111

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 29


Chapter- II : Conversion between bases

5. Binary – Octal – Binary


The approach is similar to hexadecimal conversion; however, we use groups
of 3 bits for octal representation.
Oct(8) Bin (2)
0 000
1 001
2 010
3 011
4 100
5 101
Example
6 110
11101. 010101 = 011 101. 010 101 = 0b 35.25 7 111

1 111.110 01 = 001 111. 110 010 = 0b 17.62


0b7.62 = 111 .110 010
0b5.03 = 101 .000 011
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 30
Chapter- II : Arithmetic operations

Notations dividend divisor


1111 101
-
Carry 101 11
1110 0101 Quotient
-
1110 101
+ 0
110 Reminder
10100 Borrow multiplicand

multiplier

Minuend
Subtrahend

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 31


Chapter- II : Arithmetic operations

1. Addition
Addition in binary is identical than in decimal, it relays
on 4 rules:
Example 110 6
+
1110 100 4
1110 14 1010 10
+ 110 6
10100 20
Exercise: Add the following binary numbers:
• 1+1+1+1 = 100
• 11 + 11 = 110
• 111 + 11 = 1010
• 110 + 100 = 1010 Copyright © Karim Ben Si Said L1 – INFO -2024/2025 32
Chapter- II : Arithmetic operations

2. Subtraction
• Subtraction in binary is identical to decimal. We use the
following rules
• When a borrow is required (0-1 case), we look at the
next column to the left.
110 6
• when a 1 is borrowed from the next column to the left, -
100 4
a 10 is created in the column being subtracted, and the
column from where 1 is taken becomes 0. 010 2
Example
0
We borrow 1 from the 3rd column of 1 0 1 to the 2nd column, it
becomes (0 10 1)
Column 3rd 2nd 1st
-
Before borrowing 1 0 1
After borrowing 0 10 1
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 33
Chapter- II : Arithmetic operations

2. Subtraction
Examples
• When we borrow 1 from a column containing 10, it becomes 10-1 = 1
The following table shows the steps to calculate 1010 – 111

Column 4th 3rd 2nd 1st


Borrow 1 for the 1st bit from the 2nd 1 0 1 0
We need to borrow 1 from 4th to 3rd bit 1 0 0 10
We need to borrow 1 from 3rd to 2nd bit 0 10 0 10
1010 becomes 0 1 10 10 0 1 10 10

Exercise
Calculate 24- 1 = (11000)2 – (1)2

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 34


Chapter- II : Arithmetic operations

3. Multiplication
• When we perform a multiplication between two binary numbers,
we perform a partial products between each bit of the first
number by the second number.
Example

Exercise
Calculate 15.1 x 3 in binary
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 35
Chapter- II : Arithmetic operations
4. Division Dec (10)s Bin (2)
• The division in binary follows the same procedure as division 0 00000
1 00001
in decimal 2 00010
3 00011
4 00100
Example 5 00101
6 00110
7 00111
1111 101 8 01000
-
101 11 9 01001
10 01010
0101 11 01011
-
101 12 01100
0 78 4 13 01101
15 5 14 01110
19.5 15 01111
3
16 10000
17 10001
18 10010
19 10011
Copyright © Karim Ben Si Said L1 – INFO -2024/2025 20 1010036
Chapter- II : Arithmetic operations

5. Addition in octal
• Addition in octal is identical than in decimal: if the sum of first digits is
greater than 7, add the carry to the adjacent digit to left

Example: add (71)8 and (27)8

Oct Dec
10
71 57
+
27 23
120 80

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 37


Chapter- II : Arithmetic operations
5. Addition in hexadecimal
• Addition in hexadecimal is identical than in decimal: if the sum of first digits is
greater than (F)16 = (15)10, add the carry to the adjacent digit to left

Example

1 dec
AF 175
+
21 33
D0 208

38
➢ BY THE END OF THIS CHAPTER,

The students should be able to understand:

• The basics of numeral systems (Decimal, Binary, Octal and Hexadecimal)

• Convert numbers from a base to another

• Perform the basic arithmetic operations in binary for integers and fractional numbers
(Addition, Subtraction, Multiplication and Division)

• Perfom basic arithmetic with numbers in octal and hexadecimal

Copyright © Karim Ben Si Said L1 – INFO -2024/2025 39

You might also like