Numeral System (Number system)
INTRODUCTION:
Because of its electronic structure, the computer can only
assimilate two states, "0" and "1", which is why all the information it
circulates must be expressed in the binary system.
In computing, the data processed is not always numerical; on the
contrary, it's information expressed in text form: alphanumeric
characters:0,......,9 ,A,....Z and special characters: + , >, µ, *......etc.
To introduce all this data into the machine, it must first be
encoded in binary form.
External informations0,……..9, Informations internes
CODING
a,….z, +,=, <,*, ù… (Combinaison de bits)
(Binary)
00001110 10100101
Exemple:
A CODING
(Binary) 0 1 0 0 0 0 0 1
• Types de Pure Binary code
codage
DCB (Binary Coded Decimal)
binary code
Reflected binary code (Gray
code).
ASCII code.
Bar code
The QR code
13/02/2021 2
The first coding used by humans
Morse code
Invented in 1832 (Samuel
Morse) for telegraphy, this character
coding assigns a unique
combination of signals to each letter,
number and punctuation mark.
Morse code enables alphanumeric
text to be transmitted using a series
of short and long pulses. It is
considered the precursor of digital
communication.
Reminders on numbering systems
A numbering system is defined by two elements:
• The system basis
• The system symbols
In base b , we use b distinct symbols to represent numbers.
The value of each symbol must be strictly smaller than the base b.
Each number in a base b can be written in its polynomial form.
n n 1 1 0
N (b ) C n b C n 1 b ...... C1 b C 0 b
4
The decimal system (base 10)
The decimal system that we use, uses 10 symbols: 0, 1, 2, 3, 4, 5,
6, 7, 8 and 9. A number N is written with a succession of digits
representing the coefficients of powers of 10.
Example: N(10) = (2345)10
Using powers of 10, this number can be written as:
3 2 1 0
N(10) 2 * 10 3 * 10 4 * 10 5 * 10
The Binary System (base 2)
The base of this system is 2;
only 2 symbols are used: 0 or 1.
Example: A lamp is either on (1) or off (0).
Let the number N(2) = 10101, using the general method, be
written as :N(2) = (10101)2
The octal system (base 8)
The base of this system is 8; the following symbols are
used: 0, 1, 2, 3, 4, 5, 6, 7.
Example :
Let the number N(8) = 1354, using the general method, be written
as :N(8) = (1354)8
The Hexadecimal System
(base 16)
The hexadecimal system uses 16 symbols: 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D,
E, F.
A(16) corresponds to 10(10), B(16) corresponds to 11(10), etc. (To keep a
single symbol, we have to go through the letters).
Example: Let the number N(16) = 6AF2 , using the general method, be
written as :
N(16) = (6AF2)16
Switching between bases
Change from base "b" to base "10":
let : ( N ) ( an an 1.......a1a0 ) b
( N )10 ( an b n an 1 b n 1 ...... a1 b1 a0 b 0 )
Example: Convert the number "N" to the decimal base
( N ) (10111001) 2
( N )10 (12 7 0 26 125 12 4 123 0 2 2 0 21 120 ) (185)10
Conversion from base "10" to base "b":
the principle consists of successive divisions in base "b", until a zero quotient
is obtained
Example: conversion of the number "N" to the octal base
340 8
4 42 8
2 5 8 Therefore:(340)10=(524)8
5 0
Converting from base b1 to base b2
There is no direct way to convert from base b1 to base b2.
The idea is to convert the number from base b1 to base 10, and
then convert the result from base 10 to base b2 .
? b2
b1
Development
Successive
in polynomial
10 divisions
When a base is a power of another base, switching from one to the
other is very easy and doesn't require an intermediate base,
10
Fractional number representation
A fractional number is composed of two parts
An integer part
A fractional or decimal part
345 , 567
A fractional or
integer part decimal part
Switching from base b to base10
Example1
(1110) 2 1* 23 1* 2 2 1* 21 0 * 20 (14)10
(1110,101) 2 1* 23 1* 2 2 1* 21 0 * 20 1* 2 1 0 * 2 2 1* 2 3 (14,625)10
Fractional number representation
Example2
(127) 8 1* 82 2 * 81 7 * 80
(127,65) 8 1* 82 2 * 81 7 * 80 6 * 8 1 5 * 8 2
Example3
(1101) 2 1* 23 1* 2 2 0 * 21 1* 20 (13)10
(1A7)16 1*16 2 A *161 7 *160 1*16 2 10 *161 7 *160 256 160 7 (423)10
(1101,101) 2 1* 23 1* 2 2 0 * 21 1* 20 1* 2 1 0 * 2 2 1* 2 3 (13,625)10
(43,2)5 4 * 51 3 * 50 2 * 5 1 20 3 0,4 (23,4)10
Converting from base 10 to base 2: case of a
real number
A real number is made up of two parts: the integer part and the
fractional part. The integer part is transformed by successive
divisions.The fractional part is transformed by successive
multiplication by 2 .
Example : 35,625=(?)2 0,625 * 2 = 1 ,25
I.P= 35 = (100011)2
0,25 * 2 = 0 ,5
0,5 * 2 = 1 ,0
F.P= 0,625 = (?)2
(0,625)=(0,101)2
therfore 35,625=(100011,101)2
13
Example 2: (0,6)10=(?)2
0,6 * 2 = 1,2
0,2 * 2 = 0,4 (0,6)= (0,1001)2
0,4 * 2 = 0,8
0,8 * 2 = 1,6
Note :
The number of bits after the decimal point determines the precision.
Exercise: Perform the following transformations:(23,65)=(? )2
(18,190)=(?)2
14
Conversion : binaire octal
Binary Octal
. In octal, each base symbol is written on 3 bits
in binary. The basic idea is to replace each 000 0
symbol in the octal base by its value in 3-bit 001 1
binary ( make 3-bit bursts ). 010 2
Examples : 011 3
(345)8=(011 100 101)2 100 4
(65,76)8=(110 101, 111 110)2 101 5
110 6
(35,34)8=(011 101 , 011 100)2
111 7
Note: The replacement is done from right to left
for the integer part and from left to right for the fractional part.
15
Conversion : Octal binaire
The basic idea is to make 3-bit groupings starting from the least
significant bit Then replace each grouping by the corresponding
octal value.
Example :
(11001010010110)2=(011 001 010 010 110)2=(31226)8
(110010100,10101)2= (110 010 100 , 101 010)2=(624,51)8
Note :
grouping is done from right to left for the integer part
and from left to right for the fractional part.
16
Conversion : hexadécimal binaire
Hexadéci Décimal
mal
0 0
1 1
. In Hexa, each base symbol is written on 4 bits. The 2 2
basic idea is to replace each symbol by its value in 3 3
binary on 4 bits ( make on 4 bits). 4 4
5 5
6 6
7 7
Example :
8 8
(345B)16=(0011 0100 0101 1011)2
9 9
(AB3,4F6)16 = ( 1010 1011 0011 , 0100 1111 0110 ) 2 A 10
B 11
C 12
D 13
E 14
F 15
17
Conversion : binaire hexadécimal
. The basic idea is to make 4-bit groupings starting from the least significant bit.
Then replace each grouping with the corresponding Hexa value.
Example :
(11001010100110)2=(0011 0010 1010 0110)2=(32A6)16
(110010100,10101)2= (0001 1001 0100,1010 1000)2=(194,A8)16
18
Exercice
Perform the following transformations to base 10?
(45,76)8 =(?)10
(123)6=(?)10
(1100,11)2 =(?)10
(1ABC)16 =(?)10
19
Binary arithmetic operations
Subtraction
Addition
- 0 1
+ 0 1
0 0 1(1)
0 0 1
1 1 0(1) 1 1 0
a) 11011 +10011=101110
b) 1110-1001=101
Multiplication Division
/ 0 1
* 0 1
0 ND 0
0 0 0
1 0 1
1 ND 1
c) 1101*101=1000001
d) 1001 / 11=11
Opérations arithmétiques en octal
1 1
4 3 6 5
+
4 5 1
5 8 11 6
En octal 8 s’écrit 10 En octal 11 s’écrit 13
0 3
Le résultat final : (5036)8
21
Hexadecimal arithmetic operations
4 8 6 5
+
7 A 5 1
12 18 11 6
C IN hexa 11 s’écrit B
IN hexa 18 s’écrit 12
B
2
The final result: (C2B6)16
22
Exercice
Perform the following operations and convert the result to
a decimal each time:(1101,111)2+(11,1)2=(10001,011)2
(43)8+(34)8=(77)8
(43)6+(34)6=(121)6
(AB1)16+(237)8=(B50)16
23
Types of coding in computer science
For data exchange, elementary information (bits) is manipulated in groups,
forming binary words. The size of these words is usually a multiple of 8 =
23.
The byte capacity of various components, such as memory circuits,
hard disks, etc., is often considerable, making it essential to use multiple
units of the byte.
a. Binary-coded Decimal code (DCB ou BCD)
Example:(2)
Convert
(0010)the decimal number 279 to BCD :
10 2
(7)10 (0111)2
(9)10 (1001)2
Donc (279)10 (0010 0111 1001)(BCD)
Types of coding in computer science
bReflected binary code (Gray code)
Code
Gray code is often used in situations
Code
décimal
e
binaire
Code Gray where other codes, such as binary,
0 0000 0000 can produce ambiguous or erroneous
1 0001 0001
2 0010 0011
results when transitions involve the
3 0011 0010 change of several bits in the code. For
4 0100 0110
5 0101 0111 example, in binary, when passing from
6
7
0110
0111
0101
0100
0111 to 1000, all 4 bits change at the
8 1000 1100 same time, which can lead to
9 1001 1101
10 1010 1111 intermediate states that can disrupt the
11
12
1011
1100
1110
1010
operation of a system:0111 is 7 in
13 1101 1011 decimal1111 erroneous code1000 i.e.
14 1110 1001
15 1111 1000 8 in decimal
Alphanumeric codes (character coding)
Code ASCII:
ASCII code (American Standard Code for Information Interchange). A complete
and acceptable character set must contain at least :
all 26 Capital letter,
26 Minuscule letter,
ten digits,
approximately 25 special characters such as +, -, #, %, ...etc.
Code ASCII (8 bits):
DEC OCT HEX BIN Symbole Description
8 010 08 00001000 BS Back Space Unicode (16 bits): This code
9 011 09 00001001 HT Horizontal Tab represents characters from several
languages (Arabic, Hebrew, Japanese,
11 013 0B 00001011 VT Vertical Tab
24 030 18 00011000 CAN Cancel Korean, etc.): 65536 characters.
27 033 1B 00011011 ESC Escape
Alphanumeric codes and bar codes
Unicode (16 bits):
This code represents characters from several languages (Arabic, Hebrew,
Japanese, Korean, etc.): 65536 characters.
Each writing symbol is represented by a name and a hexadecimal value prefixed
by "U+".A" Latin capital letter "A" U+0041é " Latin small letter e with acute
accent " U+00E9€ " euro symbol " U+20AC
5. Le code Barre
This marking consists of a number of
vertical bars and 13 numbers. The first
number indicates the country of origin,
the next 5 are the manufacturer's code, the
next 6 are the article code, and the 13th is
a control key.
QR codes and images,
6,Code QR :
QR" stands for Quick Response. The QR
code can contain a lot of information: 7089 numeric
characters, 4296 alphanumeric characters, as opposed
to the 10 to 13 character barcode or 2953 bytes. The
QR code can contain text, a telephone number, an
SMS, a website address, an e-mail address...etc.
7. Image coding
Images are made up of an L x H (Width x Height) matrix of elementary points,
generally referred to as pixels (short for Picture Element). Each pixel has a color
coded on a greater or lesser number of bits. The output device (screen, printer,
etc.) must render the pixels in an orderly fashion according to their respective
position (x, y) and color.
Image coding
· Black and white image 1 bit for each pixel
· Example: The ASCII character $41 can simply be
represented on a 5 x 7 matrix by "turning on" the appropriate
pixels. In this case, "color" can be represented by a single
bit (pixel on or off). The coding of an image can therefore be
summarized as a succession of pixel codings in a well-
defined order (row-column scan starting from the top left
corner).
Image with 256 colors 1 byte (8 bits) for each pixel True
color image 16 million colors 3 bytes (24 bits) for each pixe
Image size in bytes Bitmap= No. of pixels*No. of bits/pixels/8