MFC1NS
MFC1NS
The SSD can be extended in order to show the hexadecimal digits, as it is shown
in the figure 1.3.
Fig. 1.3
The SSD takes as an input a 4-bit binary number and produces as output a 7-bit
binary number. A 0 n-th bit at the output turns the n-th segment off and an 1 n-th bit turns
the n-th segment on.
1. Number systems
A number system is the totality of rules for number representation using a set of
symbols named digits.
There are two categories of number systems:
place-value number systems
additive number systems
In a place-value number system, the order in which the digits are placed dictates their
value. For instance, for the decimal number system, which is a place-value number
systems, the rightmost position in which a symbol can be placed is the units position, the
position to the left of it is the tens position, next is the hundreds position and so on.
Other place-value number systems are binary number system, octal number system,
hexadecimal number system etc.
In an additive number system, the digits have the same value whatever their positions
are. For instance, the roman number system is an additive number system.
Any place-value number system is characterized by its number of digits, named its
base or radix.
Examples
1) The binary number system has the base 2 and its digits are 0 and 1,
called bits, which is short from binary digit. The binary system is used
for representing the two possible states of a bistable device. For
example, a spot on a magnetic disk can be magnetized or not
magnetized, a transistor can be conducting or not conducting, a switch
can be open or closed.
2) The octal number system has the base 8 and its digits are 0, 1, 2, 3, 4, 5,
6 and 7. It was used first and is still used today in the assambly
language.
3) The decimal number system is the most familiar number system, it has
the base 10 and its digits are 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.
4) The hexadecimal number system has the base 16 and its digits are 0, 1,
2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F.
Hexadecimal number system is used when working directly with
memory addresses.
Theorem (Integer division theorem) For any a, bZ, b 0, there exist and are unique
the quotient qZ and the remainder rZ such that
a = bq + r and 0 r < b
Theorem (Number systems theorem) Let bZ, b > 1. For any positive integer number
N, there are the numbers n, a0, a1,..., anZ+ , 0ai <b, for 0i<n, 0<an <b, such that
N = anbn + an-1bn-1 + ...+ a1b + a0.
Moreover, these numbers are unique.
Theorem (Positive integer numbers comparison theorem) Let bZ, b > 1 and a and c
be two base b positive integer numbers, a = amam-1...a1a0(b) , c = cncn-1...c1c0(b) We have
a < c if and only if m < n or m = n and ap < cp where p = max {i | ai ci}.
i 0
i
is absurd. Thus, m n. If m < n then it is done, otherwise it means that m = n. In this case
it is obvious that ap < cp where p = max {i | ai ci}.
m m
Reciprocally, if m < n then a = aibi (b 1)bi = bm+1 -1< bm+1 bn c. Thus,
i 0 i 0
a < c.
If m = n and ap < cp where p = max {i | ai ci}, then
c – a = (cp – ap) bp + (cp-1bp-1 +...+ c0) - (ap-1bp-1 +...+ a0) >
>bp + (cp-1bp-1 +...+ c0) - bp 0. Thus, a < c.
Remark Previous theorem shows us how positive base b numbers can be compared. If
any two numbers, not necessary both positive numbers, need to be compared, then 3
cases might appear:
1. Both of them are positive. In this case use previous theorem.
2. One is a negative number and the other is positive. Obviously the negative
number is smaller than the positive one.
3. Both of them are negative a, c < 0. In this case a > c if and only if -a < -c.
Let bZ, b > 1 and a and c be two base b positive integer numbers,
a = amam-1...a1a0(b) , c = cncn-1...c1c0(b). We need to find the sum s = a + c.
We have a = a0 + a1b + a2b2 + ... + ambm and c = c0 + c1b + c2b2 + ... + cnbn.
Because a0 < b and c0 < b, it follows that a0 +c0 < 2b or, equivalently,
a0 +c0 = r1b + s0, where 0 s0 <b and the carry r1 may be 0 or 1.
More exactly,
if a0 +c0 < b then s0 = a0 +c0 and r1 = 0
if a0 +c0 b then s0 = a0 +c0 – b and r1 = 1.
Consequently,
s = a + c = s0 + (a1 + c1 + r1)b + (a2 + c2)b2 + ....
Obviously,
a1 + c1 + r1 < 2b.
Thus,
a1 + c1 + r1 = r2b + s1, where 0 s1 <b and the carry r2 may be 0 or 1.
In this manner, we can compute any digit of the sum s:
si = (ai + ci + ri )%b, for each i 0,
where r0 = 0,
0, if ai-1 ci-1 ri-1 b
ri = , for each i > 0.
1, otherwise
Remark 1)If we add two positive integer numbers a and c, each having (m +1) digits,
then the sum s = a + c has:
(m +1) digits if am + cm + rm < b or
(m + 2) digits if am + cm + rm b. In this case sm+1 = 1.
2) If the two positive integer numbers a and c have different digit numbers then:
if m > n then we consider cn+1 = cn+2 = ...= cm= 0
if m < n then we consider am+1 = am+2 = ...= an= 0
Addition algorithm;
begin
read b, m, am, am-1, ..., a0, n, cn, cn-1, ..., c0;
if m > n then
for i = n +1 to m do ci= 0;
else
if m < n then begin
for i = m +1 to n do ai= 0;
m ← n;
end;
carry ← 0;
for i = 0 to m do begin
si ← (ai + ci + carry)%b; //the remainder in the integer division
carry ← (ai + ci + carry)/b; //the quotient in the integer division
end;
if carry = 1 then
write 1, sm, sm-1, ... , s0 the digits of the sum;
else
write sm, sm-1, ... , s0 the digits of the sum;
end.
Example
''
12345(8) +
34274(8)
46641(8)
1.2.3. Integer subtraction
Subtraction algorithm;
begin
read b, m, am, am-1, ..., a0, n, cn, cn-1, ..., c0;
if m > n then
for i = n +1 to m do ci= 0;
for i = 0 to m do
if ai ci then
di ← ai - c i ;
else
begin
borrow 1 from ai+1;// ai+1 = ai+1-1
di ← b + ai - ci;
end;
while dm = 0 do
m ← m – 1;
write dm, dm-1, ... , d0 the digits of the difference;
end.
Example
A4EC(16) -
34B4(16)
7038(16)
i 0
i j
i 1
+
m
r (a , c )b .
i 0
i j
i
Example
123(5)
24(5)
-------
1102
301
-------
4112(5)
Example
2144(5) | 12(5)
12 |132
44
41
34
24
10
The second form is referred to as the expanded notation for a base b number. A
radix point separates the integer portion from the fractional portion.
We refer to an as the most significant digit of N and to a-m as the least significant
digit of N.
Let N be a base b number, N = anbn + an-1bn-1 + ...+ a1b + a0 + a-1b-1 + ... + a-mb-m .
We want to convert it into a base h number.
We convert each digit ai and the base b into base h. All the computations are made in
the target base h.
ai(b) = ci(h) for any i, -m i n
10(b) = x(h).
Thus, N(b) = (cnxn + cn-1xn-1 + ...+ c1x + c0 + c-1x-1 + ... + c-mx-m)(h).
Example For converting 234(5) into a base 2 number, we convert each digit and the
original base into target base 2:
2(5) = 10(2), 3(5) = 11(2), 4(5) = 100(2), 10(5) = 101(2).
Thus, 234(5) = (2*52 + 3*5 + 4)(5) = (10*1012 + 11*101 + 100)(2) =
(10*11001+1111+100)(2) = (110010+1111+100)(2) = 1000101(2).
Particular case
If b = hk then we convert each digit from the base b number into a k –digit base h
number and we juxtapose these numbers.
Example For converting 5436(8) into a base 2 number, we convert each digit into 3-digit
base 2 number because 8 = 23.
5(8) = 101(2) , 4(8) = 100(2) , 3(8) = 011(2) , 6(8) = 110(2).
Thus, 5436(8) = 101100011110(2).
.....
[Nn'](b) = cn', so we can determine cn'.
Now we have to convert {N}(b), the fraction portion of N(b) into base h. We can
write
{N}(b) = c-1h-1 + c-2h-2 +... + c-m'h-m',
where we do not know the digits c-1, c-2,...,c-m', but we can determine them by a sequence
of multiplications by h.
{N }( b ) h c1 c 2 h 1 c- 3h 2 ... c m 'h m '1 , so we can determine c-1,
{ N 1 }( b )
....
{N m '1}( b ) h c m ' , so we can determine c-m'.
Consequently, N(b) = anan-1...a1a0.a-1...a-m(b) = cn'cn'-1...c1c0.c-1...c-m'(h).
Particular case
If h = bk then, starting from the radix point to the left and to the right, we group the
base b digits into sequences of length k, if necessary adding insignificant zeros at the end
of the rightmost group after the radix point. Each group can be interpreted as a base h
digit.
Example For converting 1101110111001(2) into a base 8 number, we group the digits
into sequences of length 3 because 8 = 23:
1
101110
111001 = 001
101 110111001 .
We know that 001(2) = 1(8) , 101(2) = 5(8) , 110(2) = 6(8) , 111(2) = 7(8).
Thus, 1101110111001(2) = 15671(8).
Example For converting 10011111.11001(2) into a base 16 number, we group the digits
into sequences of length 4 because 16 = 24:
1001
1 = 1001
1111.1100 1111.11001000
We know that 1001(2) = 9(16), 1111(2) = F(16) , 1101(2) = D(16) , 1000(2) = 8(16).
Thus, 10011111.11001(2) = 9F.D8(16).
This method is usually used when we make hand computations for converting a base
b number into a base h number, where b, h 10. Because base 10 arithmetic is more
familiar to us, we prefer to do all the computations in base 10, so we will use base 10 as
an intermediate base. This method consists of:
1. converting the base b number into a base g number with computations made in
base g, followed by
2. converting the base g number into a base h number with computations made in
base g
Example For converting 111442(5) into a base 8 number, it seems easier to use base 10 as
an intermediate base. First we convert 111442(5) into a base 10 number in the following
manner:
111442(5) = (1*55 + 1*54 +1*53 +4*52 +4*5 +2)(10) = 3997(10).
Now, we need to convert 3997(10) to a base 8 number:
3997 = 499*8 + 5
499 = 62*8 + 3
62 = 7*8 + 6
7 = 0*8 + 7
Thus, 3997(10) = 7635(8) and 111442(5) = 7635(8).