Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

1 Laboratory work №1. Number systems.

Converting from any number system


to another. Arithmetic operations in the number systems

Goal of the laboratory work is to converting from any number system to


another and perform arithmetic operations in the number systems.

The theoretical information

1.1 Number systems


The number system is a set of methods for recording numbers using digital
signs. Depending on the way the numbers are represented, number systems are
divided into positional and non-positional.
In a positional number system, the quantitative value of each digit depends on
its place (position) in the number. In a non-positional number system, numbers do
not change their quantitative value when changing their location in number.
Example: A positional number system is an Arabic decimal system in which
10 digits (from 0 to 9) are used to represent numbers. Non-positional number system
- Roman, in which a specific combination of characters is used for each number. In
such a system, 7 characters are used: I, V, X, L, C, D, M, which correspond to the
value: I (1); V (5); X (10); L (50); C (100); D (500); M (1000). For example: III -
three; LIX - fifty nine; DLV - five hundred and fifty-five.
The disadvantage of non-positional number systems is the lack of formal rules
for writing numbers and arithmetic operations.
Traditionally, Roman numerals are often used in the numbering of Chapter in
books, centuries of history and so on.
In a positional number system, the number of different digits used to represent
a number is called the base of the number system. The position of a digit in a number
is called a category. And the value of each category is its weight. For any number
system, the rightmost number is the least significant digit, and as you move to the
left, the weight of the discharge increases by a number equal to the base of the
number system.
Any real number N specified in the p-th number system can be written in
expanded form:
N=Σai×pi= an×pn+an-1×pn-1+...+a1×p+a0+a-1×p-1+a-2×p-2+...a-m×p-m
p - integer positive number (base of the number system ); a i-integer (0 ≤ ai ≤ p-
1), called positional discharge; n is the number of digits in the integer part of the
number; m is the number of digits in the fractional part of the number.
A any number in the p-th number system can be written as a sequence of
numbers. That is, the representation of the number N in folded form:
N=(anan-1…a1a0,a-1…am)p
The computers used the decimal number system for inputting and outputting
data. For the computer uses a binary number system. The numbers 0 and 1 are used
to record numbers in this system. The choice of the binary system is explained by the
fact that the electronic elements can only be in two clearly distinguishable operating
states. According to the Neumann principle: "the computer performs arithmetic
calculations in the binary number system."
It is inconvenient to use a binary system with its enormous record to represent
information outside a computer. Therefore, for compiling programs, they use the 8th
and 16th number systems.
1.2 Converting from any number system to another.
To represent one digit of the octal number system are used three binary digits
(triad), and hexadecimal - four binary digits (tetrad).
To convert an octal or hexadecimal number to a binary number system, it is
enough to replace each digit of this number with the corresponding three-digit binary
number (triad) or four-digit binary number (tetrad) (Table 1.1) and discard the
insignificant zeros in the upper and lower digits.
Example. (85A)16 =(100001011010)2
8=1000
5=0101
A=1010
To convert from binary to octal or hexadecimal: moving from the point of
separation of the integer and fractional parts of the number left and right, they break
the binary number into groups of three or four digits, supplement the left and right
groups with zeros if necessary. Then the triad or tetrad is replaced with the
corresponding octal or hexadecimal digit.
Example. (111100111)2 =(1E7)16
0001=1
1110=E
0111=7
Translation from octal to hexadecimal and vice versa is done through the
binary system using triads and tetrads.
Table 1.1 - The relationship between binary, octal and hexadecimal
Binary Octal Decimal Hexadecimal
(Base 2) (Base 8) (Base 10) (Base 16)
triad tetrad
0 0 000 0 0 0000
1 1 001 1 1 0001
2 010 2 2 0010
3 011 3 3 0011
4 100 4 4 0100
5 101 5 5 0101
6 110 6 6 0110
7 111 7 7 0111
8 8 1000
9 9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
Converting from any number system to decimal carry out by presenting the
number in the form of a power series with the base of the system from which the
number is converted, that is, the number is written in expanded form. Then, the value
of the sum is calculated, and all arithmetic operations are carried out in the decimal
system.
Example.(111)2=1×22+1×21+1×20=(7)10
(365)7=1×72+1×71+1×70=(57)10
A conversion from decimal to any other number system. In order to convert an
integer from a decimal number system to another number system with a base p, you
must perform the following steps:
1) Divide this number on the basis of a new number system p;
2) Transfer the remainder of the division into a new number system; the least
significant digit of the new number is obtained ;
3) If the quotient of the division is greater than the basis of the new system p,
continue the division; a new remainder converted to a new number system gives the
second digit of the number, etc.
4) The last quotient of the division is the senior digit of the new number.
Example.(111)10=(1101111)2,(9780)10=(2434)16
111/2=55, Remainder 1 9780/16=611, Remainder 4
55/2=27, Remainder 1 611/16=38, Remainder 3
27/2=13, Remainder 1 38/16=2, Remainder
4 13/2=6 , Remainder 1 2/16=0, Remainder 2
6/2=3, Remainder 0
3/2=1, Remainder 1
1/2=0. Remainder 1
The number in the new number system is written in the form of remainders
from division.
The rule for transferring fractions from any number system to another is to
perform the following actions:
1) multiply the fractional part of the number by the base of the number system
p;
2) in the resulting work, select the integer part of the number and transfer to a
new number system - this will be the highest order of the desired number;
3) the fractional part of the work again multiplied by the base of the new
number system p; the whole part of the product will be the next bit of the fractional
part of the desired number;
4)Repeat paragraph 3 until the required number of digits of the desired number
is obtained. The result obtained is approximate. In order to somehow achieve the
accuracy of the translation, you should use the following rule:
am/10m < 1/pk, where am is the last digit of the decimal fraction, m is the
position of this digit, p is the base of the new number system, k is the number of bits
of the fractional part in the new number system.
Example. Transfer (0.784)10 → (? )2, 0.612510 → (?)8 and (0.378)10 → (?)16.
Leave four decimal places.
0,784 ×2=1,1568 1 0,6125×8=4,9 4 0,378×1=6,048 6
0,568×2=1,136 1 0,9×8=7,2 7 0,048×16=0,768 0
0,136×2=0,272 0 0,2×8=1,6 1 0,768×16=12,288 12
0,272×2=0,544 0 0,6×8=4,8 4 0,288×16=4,608 4,
0,544×2=1,088 1
The result is obtained by reading the numbers from top to bottom: 0.784→
0.1100, 0.6125→ 0.4714, 0.378 → 0.60С4.

1.3 Arithmetic operations in the number systems


1.3.1 Addition and subtraction in octal notation.
When performing addition and subtraction in the octal number system, the
following rules should be observed:
 there can be used only the digits of the octal alphabet in the record of the
results of addition and subtraction;
 the octal number system includes 8 digits, the overflow discharge occurs
when the result of addition is bigger than or equal to 8. In this case, to record the
result, you must subtract 8, write the remainder, and add the overflow unit to the
higher bit;
 if you subtract one in the highest digit, this unit is transferred to the lower
order in the form of eight units.
For example:
a)+5478 b)-5478
4728 4728
12 418 5 58

1.3.2 Addition and subtraction in hexadecimal notation


When performing these actions in the hexadecimal number system, the
following rules must be observed:
1) when writing the results of addition and subtraction, we must use the digits of the
hexadecimal alphabet: the numbers denoting the numbers from 10 to 15 are written
in Latin letters (A, B, C, D, E,F), so if the result is a number from this interval, it
must be written with the corresponding Latin letter;
2) the hexadecimal number system includes only 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D,
E, F, i.e. overflow of the discharge occurs if the result of addition is bigger than or
equal to 16, and in this case, to record the result, you subtract 16, write the
remainder, and add to the senior category the overflow unit;
3) if you have to occupy a unit in the highest digit, this unit is transferred to the lower
order in the form of sixteen units.
For example:
a)+164A16 b)-164A16
7AC16 7AC16
1FF616 E9E

1.3.3 Arithmetic operations in binary number system


1. The addition operation is performed using a binary addition table in the same
bit For example:
a) +10012 b) +11012 c) +111112
10102 10112 12
100112 110002 1000002
2. The subtraction operation is performed using a
subtraction table For example:
а) –1011100112 b) –1101011012
1000110112 1010111112
0010110002 0010011102

You might also like