Numeration systems and codes
Numeration systems and codes
The base of a numbering system is the number of different digits or symbols used in that
system. A number N in any base B is given by (N)B .
N=𝐴𝑛𝐵𝑛
+ 𝐴𝑛-1𝐵𝑛-1 + 𝐴𝑛-2𝐵𝑛-2 + 𝐴𝑛-3𝐵𝑛-3 +......+𝐴0𝐵0 + 𝐴-1𝐵-1 + 𝐴-2𝐵-2 ... ... 𝐴-𝑚𝐵-𝑚 :
This representation is called a polynomial form Note: ∀ 𝒙 ∈ 𝑰𝑹, 𝒙𝟎 = 𝟏 and 𝒙−𝒎 =𝒙𝒎
𝟏
Page 3
DIGITAL CIRCUIT COURSES
The least significant bit is called LSB (Lest Significant Bit) and is most often found at
right-hand side of a binary number.
010011:
MSB LSB
Example: (1101)2
Bit 1 1 0 1
Rank 3 2 1 0
23 22 21 20
Weight
Weighting 8 4 2 1
(1101)2 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = (13)10 = 13
Sign 5 0 2 7 1
Rank 2 1 0 -1 -2
82 81 80 8-1 8-2
Weight
Weighting 64 8 1 1/8 = 0,125 1/82 = 0.015625
Sign F 5 9 B A
Rank 3 2 1 0 -1
16-1
Weight 163 162 161 160
Weighting 4096 256 16 1 1/16 = 0,0625
Page 4
DIGITAL CIRCUIT COURSES
(A3F9)16 = 10 x163 + 3x162 + 15x161 + 9x160 = 40960 + 768 + 240 + 9 = (41977)10 = 41977
Page 5
DIGITAL CIRCUIT COURSES
2ème method: 107 = 64+ 32 + 8 + 2 + 1 = 1x26 + 1x25 + 0x24 + 1x23 + 0x22 + 1x21 + 1x20
(41977)10 = ( ? )16 (41977)10 = ( A3F9 )16
(189)10 = ( ? )8 (189)10 = (275)8
41977 16
189 8 41968 2623 16
184 23 8 9 2608 163 16
5 16 28 15 160 10 16
0 0 3 0 0
7 F
2 10
A
Page 6
DIGITAL CIRCUIT COURSES
(3042)5 = 3 × 53 + 0 × 52 + 4 × 51 + 2 = (397)10
(𝟑𝟎𝟒𝟐)𝟓 = (𝟏𝟖𝑫)𝟏𝟔
Page 7
DIGITAL CIRCUIT COURSES
Decimal DCB
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
(238)10 = (0010 0011 1000)DCB
3 0 0 1 1
4 0 1 0 0
NB: To code any other number from another
5 0 1 0 1
system (binary, octal or hexadecimal) in DCB,
6 0 1 1 0
7 0 1 1 1 first convert it to decimal and then find its 4-bit
8 1 0 0 0 binary equivalent (DCB).
9 1 0 0 1
Page 8
DIGITAL CIRCUIT COURSES
This code is also called code 8.4.2.1, which are the respective weights of the bits in each quartet.
Correspondence table Decimal - Pure binary - Increased by 3
9 2 +7
Decimal code
+ +
3 3 3
(𝟗𝟐𝟕)𝟏 𝟎 = (𝟏𝟏𝟎𝟎𝟎𝟏𝟎𝟏𝟏𝟎𝟏𝟎)𝑴𝒂𝒋𝒐𝒓é 𝟑
12 5 10
Page 9
DIGITAL CIRCUIT COURSES
14 (1 1 1 0
+ + +
)2 (𝟏𝟒)𝟏𝟎 = (𝟏𝟏𝟎)𝟐 = (𝟏𝟎𝟎𝟏)𝑮𝒓𝒂𝒚
(1 0 0 1 )Gray
To decode a number in GRAY code to its decimal equivalent, we first convert the Gray number
to its natural binary equivalent and then reproduce the most significant bit, then proceed as follows:
c) ASCII code
ASCII code (American Standard Code for Information Interchange).
This is a widespread code used in virtually all computers to exchange information between a
CPU and peripherals such as keyboards, printers, consoles, etc... It is part of one of the alphanumeric
codes and is widely used to code the keyboard keys of these digital machines. It generally comprises 7
bits of information and offers 27 , i.e. 128 possible characters. (And sometimes 1 parity bit).
Page 10
DIGITAL CIRCUIT COURSES
Example
Keyboard keys ASCII code Keyboard keys ASCII code
0 0110000 a 1100001
1 0110001 b 1100010
2 0110010 s 1110011
9 0111001 ( 0101000
A 1000001 & 0100110
B 1000010 = 0111101
C 1000011 + 0101011
D 1000100 DEL 1111111
E 1000101 ! 0100001
Y 1011001 ? 0111111
Several other codes are used, such as Barre, Aïken, Unicode, EIA (Electronic Industries
Association)...
Page 11
DIGITAL CIRCUIT COURSES
b) Subtraction
c) Multiplication
Page 12
DIGITAL CIRCUIT COURSES
c) Division
✓ Begin addition with the least significant digits as in decimal, mentally replacing letters with
their decimal equivalents.
✓ If the sum is ≥ 16, subtract 16 from this sum and transfer 1 seizaine to the left-hand row.
1 1 1 1
58E 7AD45
+ +
A22 B0CF8
FB0 12BA3D
b) Subtraction: The procedure is the same as for decimal.
Note: (-1)10 = (FFFFF...)16
-CD0 3D58
4E5 0 -5: impossible,
1 -29F7
1 We borrow 1 seizaine from D,
80B which
1361 which makes (0 + 16) - 5 = 11 = B
Page 13
DIGITAL CIRCUIT COURSES
1F3
1 1 1
3xC +1= 37 = (16 x 2) + 5, We write 5 and retain 2 seizaines.
3x5 + 2 = 16 = (16x1) + 1; We write 1 and retain 1 seizaine and this 1
1
115CE will be brought forward because the operation is complete.
E
this retained 5 will be brought forward because operation completed.
Etc ...
5
+ + 0101 253
+421 +
0010 0101 0011
3 0011 0100 0010 0001
8 1000 674 0110 0111 0100
6 7 4
b) The sum of two digits > 9:
By adding two BCD-coded digits, we can obtain six forbidden or invalid representations. These
are: 1010, 1011, 1100, 1101, 1110, 1111. These representations do not exist in BCD code.
Page 14
DIGITAL CIRCUIT COURSES
In such a case, the sum must be corrected by adding 6 (0110) to take into account the fact that six
invalid coded presentations have been skipped.
For example:
In some cases, the carry can be transferred from the first least significant quartet to the next at the
very first stage of the operation.
Example:
78 0111 1000
+
39 0011 1001
117 1011 0001
+ 0110 1st correction
+1011 0111
0110 2nd correction
00010001 0111
1 1 7
c) Recapitulation of addition in BCD:
Page 15
DIGITAL CIRCUIT COURSES
In addition, there are a number of notations for handling these numbers. Negative numbers will be
represented on the same word length as positive numbers.
A certain convention must be adopted to represent the sign of a number; to do this, another bit is
added to the number, called the sign bit or number bit, and placed at the extreme left of the binary
number. Positive numbers will have "0" as their sign bit, and negative numbers "1".
+3 = 0011 ; -3 = 1011
The 2's complement is widely used as the natural representation of negative numbers. The 2's
complement of a number is obtained by adding 1 (to the LSB) to its 1's complement.
C2 (N) = C1 (N) + 1
24 = (11000)2 = ( 0 0 1 1 1 ) C1
+ 1
( 0 1 0 0 0 ) C2
Here's how to write signed binary numbers using 2's complement notation.
✓ If the number is positive, its magnitude is the exact binary magnitude and its sign bit is
a 0 in front of the most significant bit.
Example: C2 (+45) =
(+45) =10 0 1 0 1 1 0 1
Sign bitExact size
Page 16
DIGITAL CIRCUIT COURSES
✓ If the number is negative, its magnitude is the 2's complement of the exact magnitude
and its sign bit is a 1 to the left of the most significant bit.
(- 45) =10 1 0 1 0 0 1 1
Sign bitComplement to 2 of 45
NB: The 2's complement of a signed number transforms a positive number into a negative number and
vice versa. (The 2's complement of the 2's complement of a number gives the number itself).
+9 0 1001
+
+4 0 0100
+ 13 0 1101
Sign bit
b) Case of a positive number and a smaller negative number
Add +9 and -4 over 5 bits
1 1
+9 0 1001
+
-4 1 1100
+5 1 0 0101
Overflow Sign bit
( Not taken into
consideration)
Note that the sign bits are also added. In fact, a carry is produced when the last row is added.
This carryover is still called overflow and is always rejected, hence the final sum of 00101, i.e. the
decimal number +5.
Page 17
DIGITAL CIRCUIT COURSES
-9 1 0111
+
+4 0 0100
-5 1 1011
Sign bit
In this case, the sign bit of the sum is 1, indicating a negative number. As the sum is a negative
number, the answer is the 2's complement of the exact magnitude. So 1011 is actually the 2's complement
of the sum. To find the exact magnitude of the sum, we need to take the 2's complement of 1011, which
gives 0101 = (5); the answer is therefore 11011 = -5.
The result can also be checked by adding the weight of each bit, with the sign bit worth -2N,
where N is the number of bits of magnitude.
-9 1 0111
+
-4 1 1100
- 13 1 1 0011
Overflow Sign bit
( Not taken into
consideration)
The final result was again negative (-13).
Notes : A subtraction operation involving numbers expressed in 2's complement notation is in reality an
addition operation that differs little from the cases examined above.
Page 18
DIGITAL CIRCUIT COURSES
Exercise 2
1) A microcomputer can store 16 bits in each of its memory locations. If the range of memory
addresses is from (0000)16 to (𝐹𝐹00)16, say how many memory locations this computer has.
2) Another microcomputer has 10240 memory locations. Give its address range in hexadecimal,
starting at address (1000).16
Exercise 3 Exercise 5:
Perform the following conversions: Perform the following operations in the
a) (1101011)2 = (? )16 = (? )10 = (? )8 indicated bases
b) (10110111,0110)2 = (? )3 = (? )5 1) (3𝐷7𝐸)16 × (𝐵2𝐴)16
c) (2567)10 = (? )2 = (? )8 = (? )16 2) (5𝐵𝐹)16 + (4𝐶𝐵)16
d) (1936,45)10 =?2 = (? )16 = (? )𝐷𝐶𝐵 3) (4756)8 + (3527)8
e) 107.8125 = ( ? )8 = ( ? )2 = ( ? )16 4) (175214)8 - (152405)8
f) (2𝐴𝐸𝐶)16 = (? )𝐺𝑅𝐴F = (? )𝐷𝐶𝐵 = (? )𝐸𝑋𝐶𝑒𝑠𝑠 3 5) (2)𝐵𝐶𝐷 + (5)𝐵𝐶𝐷
g) (0.09375)10 =?2 6) (6)𝐵𝐶𝐷 + (4)𝐵𝐶𝐷
h) (3623.71)16 = ( ? )10 = ( ? )8
7) (08)𝐵𝐶𝐷 + (09)𝐵𝐶𝐷
i) (𝐹2𝐴)16 =?2 =?𝐷𝐶𝐵 =?8 =?𝐺𝑅𝐴F
8) (47)𝐵𝐶𝐷 + (35)𝐵𝐶𝐷
j) (1001100111111)𝐷𝐶𝐵 =?10 =?8 =?16
Exercise 4: Exercise 6:
1) Perform the following operations in base 2 1) Write the following numbers in 8-bit 2's
a) 0,1011 + 0,111 complement code: +1 ; -1 ; -55 ; 22,
b) 1011,110 + 11,1 +127, - 127, -128 ; +129 ; - 129.
c) 0011 - 1111 2) Perform the following 8-bit signed
d) 1110 -1011 integer operations, including the sign bit
e) 1011 x 1011 a) (+17) + (-12)
f) 101,101 x 0,1101 b) (-63) + (+28)
g) 111111 / 1001 c) (+63) + (-28)
d) (+35) + (+65)
e) (-35) + (-28)
Page 19