0% found this document useful (0 votes)
22 views15 pages

INF EP1 Sist Numeracio ENG

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views15 pages

INF EP1 Sist Numeracio ENG

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Pevious study 1: Numeration systems

Realization: Individual. You need to solve the proposed exercises and bring them to the
SD1 problems session.

Numbering systems are a way of encoding or representing information, in particular


allowing value information to be represented using numerical numbers. In this text the
following ones will be seen:

• A system that represents natural numbers, i.e. positive integers, using only 0's and
1's (Natural binary system);

• A system that allows to represent the integer values, also using only 0's and 1's (2-
snap);

• And a system that allows you to render the decimal values, using only 0's and 1's
(floating point system).

All these systems are binary systems, i.e. they only use numbers 0 and 1 and are
systems that use computers to represent numerical values in their memory.

Note: All the theoretical concepts necessary for the realization of this directed work are
contained in the following section. On the day of the SD1 problem session, the solution to
the proposed exercises will be debated and doubts will be resolved.

1. Theory
1.1 Numbering system in natural binary
This numbering system allows to represent all the natural numbers in the binary system, that is,
using the numbers 0 and 1.

The fundamental theorem of numbering shows us how to represent a number according to the
base in which it is represented. Thus, in a base B system, any number no one can be represented
by a power polynomial of the base B, each multiplied by a system-owned symbol. That is:

n
N= ∑ ai b
i

i=− p

where B is the base of the numbering system and a number belonging to the system that,

therefore, fulfills the condition ; and p represent the number of full and
fractionary digits respectively.

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 2

In this representation of the numbers the value is by position, that is, it is a weighted code: We
know the value of the number for the position that occupies each digit within its representation.
A digit in the position and has a bi weight.

Thus, given a number represented in natural binary, we can obtain its value in decimal applying
this theorem:

1011,112=1 ×23 +0 ×22+1 ×21 +1×20 +1 ×2−1 +1×2−2 =8+2+1+0,5+0,25=11,75

Conversion of a decimal number to base 2: This conversion is made in two steps

First the whole part is converted via the entire division theorem. This method consists of a
succession of divisions of the value N10 (expressed in the decimal system) by the value of the
base b (in the case of the binary system will be successive divisions by 2) in which we are
running with the waste and the last quotient.

In the second step, for the frthe part, we do a process of multiplications successive by the base
(b = 2 in the binary system) and we are sticking with the whole digits.

Example: Number to convert: 117,812510

Conversion of the whole part:

11710=11101012

Conversion of the fractionary part:

0,812510=0,11012

The final number on base 2 is: 117,812510=111010,11012

1.2 Numeration system in Complement at 2


Complement at 2:The complement to 2 is the method most used to represent or encode in
binary the whole numbers on computers. This method allows to represent the whole numbers,

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 3

namely positive and negative, and also allows to operate with them in an easy way fulfilling all
the norms of arithmetic.

The complement to 2 is a method that serves to calculate the inverse of an X value with respect
to the addition operation. That is, given an X value, its inverse with respect to the sum is
himself changed of sign, – X, since X + (– X) = 0. A compact way of expressing this is:

–X = C2(X)

It can also be written: X = –C2(X), X = C2(–X) i C2(–X) = –C2(X).

Calculation: To get the complement to 2 (C 2) of a binary number you have to get the
complement to 1 (C1) and add it "1":

C2(X) = C1(X)+1

The complement at 1 (C1) of a binary number is obtained by exchanging the "1" and "0".

Example: Given the binary number coded with 5 bit X = 10001, its complement to 1 is

C1(X)=C1(10001)=01110.

And its complement to 2 is

C2(X) = C2(10001) = C1(10001) + 1 = 01110 + 1 = 01111.

Sign Bit: In a number encoded in C 2 the first bit (the most to the left) is the sign bit. If the sign
bit is "0", the number is positive. If the sign bit is "1", the number is negative.

Example: Consider encoding in C2 with 5 bits, then

X = 01111 is a positive number (the first bit on the left is 0)

Y = 11111 is a negative number (the first bit on the left is 1).

Range of representable numbers: In the encoding in C 2, if we use n bits, we can only


represent the X values such as

–2n-1 ≤ X < 2n-1

In contrast, the representation range in natural binary is

0 ≤ X< 2n.

It is important to note that negative numbers cannot be represented in natural binary.

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 4

Example: Suppose we use 5 bits n = 5 bits, then:

En binari natural podrem representar els números X tals que 0 ≤ X< 25 = 32. Així el primer
número serà el zero, 00000B = 0D, i el darrer serà el 11111B = 31D.

In natural binary we can represent the numbers X such that 0 X < 2 5 = 32. So the first number
will be the zero, 00000B = 0D, and the last one will be 11111B = 31D.

En C2 podrem representar els números X tals que –24 ≤ X < 24, és a dir,–16 ≤ X < 16. Així, el
primer número serà el –16D i l’últim serà el +15D.

In C2 we will be able to represent the numbers X such that – 2 4 ≤ X < 24, ie – 16 ≤ X < 16.
Thus, the first number will be the – 16D and the last will be the + 15D.

Codification method to C2: First of all, always look if the number of bits n is sufficient to
encode the desired number X, that is, we must see if the number to encode is in the range
.

If this is satisfied, we must proceed differently if the number X is positive or negative.

• If X is positive, simply find your natural binary and add to the left as many 0's as necessary
to complete the number of bits to have the number (this representation will already be the
encoding to C2 number X).

• If X is negative, we will have to find the natural binary of the number X without taking into
account the sign and add to the left as many 0's as necessary to complete the number of bits that

must have the number, and then apply the formula .

Example: Encoding of a positive value. Suppose we use n = 5 bits We want to encode to C 2 the
number 5D.

Because n = 5, we can ony code the numbers X such as –24 ≤ X < 24, which means,
. Therefore, 5D can be coded to C2.

The codification to C2 of the positive number 5D is directly his natural binary,, 101 and add to
the left so many 0's as necessary to complete the number of bits that the number must have, that
is: 00101

Note that the sign bit indicates that, indeed, it is a positive number.

Example: The encoding of a negative value. Suppose we use n = 5 bits We want to encode C2
the number –6D.

Because n = 5, we can only codenumbers X which –24 ≤ X < 24, that is, .
Therefore, –6D can be coded to C2.

First we need to find 6 D's natural binary. 6D's natural binary is 110 and it will add to the left so
many 0's as it is necessary to complete the number of bits the number must have, namely: 00110

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 5

The following formula applies:

C 2 ( 00110 )=C1 ( 00110 )+1=11001 +1=11010

Note that the sign bit indicates that, indeed, it is a negative number.

Example: Suppose we use n = 5 bits, and we want to encode to C 2 numbers – 16D, 15D and 16D.
Because n = 5, we can only encode X numbers such as – 2 4 ≤ X < 24, ie. Therefore, 16 D cannot
be encoded into C2. Instead – 16D and 15D are in the range and yes can be encoded.
The encoding in C2 of the positive number 15D is directly its natural binary, 01111. Note that
the sign bit indicates that, indeed, it is a positive number.
And to encode the negative number – 16D, first we need to find the natural binary of himself but
without sign, 16D. The natural binary of 16D is 10000. The following formula applies:

Note that the sign bit indicates that, indeed, it is a negative number.

Table 1 indicates how to interpret a binary number depending on whether it has been encoded in
natural binary or C2.
Natural C2
000 0 0
001 1 1
010 2 2
011 3 3
100 4 -4
101 5 -3
110 6 -2
111 7 -1
Table 1
Notice the sign bit in the column of the C2.

Conversion from C2 to decimal:


Before converting an encrypted number to C 2 to decimal, it is necessary to look at the sign
bit, and depending on the one we will proceed in one way or another.

• If the number binary X encoded in C 2 has positive sign bit, the conversion to decimal is
performed as we would in the encoding in natural binary.

• If the number binary X encoded in C 2 has negative sign bit, then we must calculate

before the conversion to decimal (that is, we have to change the sign to be able to
apply the same method as for positive numbers).

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 6

Example: Suppose a codificacation C2 with n = 5bits.


If the number binary X encoded in C2 has positive sign bit
X = 01110B is a positive number, therefore, its decimal equivalent is:
X = 23+22+2 = 8+4+2 = 14D.

If the number binary X encoded in C2 has negative sign bit

X = 10010B is a negative number, therefore, its decimal equivalent is:

X = 10010C2 = –C2(10010) = –[ 01101+1] = – 01110 = –[23+22+2] = –14D.

Operations: the encoding in C2 allows to make easy sums and remains. To perform the rest X
– Y you need to find the encoding in C2 of – Y and simply make the binary sum X + (– Y).

Example:To perform the operation 37D – 25D, with a coding in C2 with n = 8 bits, we must do
the following:

Encode + 37D: To be positive, simply find the natural binary and add to the left as many 0's as
needed to complete the 8 bits to have the number, 00100101.

Encode – 25D: To be negative, we must encode 25D in natural binary using 8 bits, 00011001,
and then find your C2, – 25D = C2 (00011001) = 11100110 + 1 = 11100111.

Perform the binary sum: Notice that we must discard the first "1" since the representation is 8
bits.

We can also check that the result 00001100C2 corresponds to 12D.

Overflow: Overflow occurs when the result of the sum of two positive numbers or two negative
numbers is out of the range of representable numbers for the precision (bit number, N) chosen.

The sum of a positive number and a negative number can never cause overflow in the
representation to C2, since the result of this sum will be a value greater than the negative number
and at the same time smaller than the positive number and therefore will be representable with
the number of bits used. On the other hand, the sum of two positive numbers or two negative
numbers can lead to overflow.

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 7

Example: Consider the numbers in table 1, where the encoding has been done with n = 3 bits.

If we want to add 2 + 3 We see that the result is 5, is out of the range of representation with 3
bits (with 3 bits we can only represent numbers from-4 to 3). Thus, it is said that in this
operation, 2 + 3, has occurred overflow and therefore the result is incorrect.

Similarly, for the negative numbers, the operation also produces overflow and therefore the
result is incorrect.

When overflow occurs the result of the operation in binary is wrong.

Example: Following the example above, the sum of 2 and 3 in C 2 gives the resultat101 that, in
C2, corresponds to-3 (!).

When working with the encoding in C2, the overflow is detected with the help of the sign bit.

• If you add two positive numbers to the result is a negative number (the sign bit of the result is
a "1"), that means that it has occurred overflow and that, therefore, the result is incorrect.
Obviously, the sum of two positive numbers can not result in a negative value.

• If you add two negative numbers the result is a positive number (the sign bit of the result is
"0"), that means it has occurred overflow and that, therefore, the result is incorrect. Obviously,
the sum of two negative numbers cannot result in a positive value.

Example: Consider coding aC2 with n = 5 bits. If we try to add + 10 D and + 6D, the result of the
binary sum is:

Where the sign bit of the result is a "1" (negative). The result is therefore incorrect (the sum of
two positive numbers can not be a negative number). In C2 10000C2 corresponds to – 16D.

It has occurred overflow since the correct result, + 16 D, is not representable in C 2 with n = 5 bits,
is out of range (with 5 bits the largest representable number is the + 15 D).

Representation del zero: In the encoding on C2 Zero representation (both positive and
negative) is unique. For example, for n = 5 bits, we have:

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 8

+0D=00000C2 (Natural binary, positive sign bit)

–0D=C2(0D)=C1(00000)+1=11111+1=100000B=00000C2 (As the representation is at 5 bits, we


discard the first "1")

1.3 Floating point numbering system


Floating point representation is a form of scientific notation that allows to represent extremely
large and extremely small numbers. The standard for representing real numbers in floating
point on computers is the IEEE 754.
The IEEE 754 standard defines four formats for the value representation in floating point:
 Simple precision (32 bits)
 Double precision (64 bit)
 Extensive simple precision
 Extensive double precision
Here we will only try the simple representation with 32 bits.
Floating point representation is used to represent real numbers using one or several, which can
be very large or very small. The problem with floating point representation is that the numbers
can only be represented (as we only use 32 bits), that is, with a certain error. This error is
negligible in the case of very small numbers, but is not so small for the case of large numbers,
although the relative error is always the same.

The starting point is the representation in scientific notation of a real number encoded in binary.

Example: The real number


-10111,0110101
Can be expressed in scientific notation as:
-1,01110110101 × 24
Where the base is 2 because it is a binary number, the exponent is E = 4, the sign is negative and
the mantissa is 01110110101.

Simple precision floating point representation: In this representation are used 32 bits, of
which the first corresponds to the bit of sign S, the following 8 correspond to the encoding of
the exponent and the remaining 23 correspond to the encoding of the mantissa.
1 bit 8 bits23 bits
s Exp = e+127m

32 bits

If the sign of the number to encode is positive, then s = 0; If it is negative, s = 1.

Example: If we apply the floating point format to the number in the previous example,
-1,01110110101 × 24,

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 9

We have:
The sign bit is S = 1 as it is a negative number;
The exponent is encoded as EXP = 4 + 127 = 131 which, passed to binary, is 10000011;
M is the number mantissa with both zeros as well as necessary to fill the 23 bits,
m = 01110110101000000000000.
Thus, the result is:
1 1000001101110110101000000000000

Range of representation: Notice that the decalage EXP = e + 127 is made to be able to
represent very large numbers and very small numbers, because it is necessary to take into
account that this system allows to represent:
• Zero.
• Real numbers.
• The infinite.

Type Exp Mantissa

Zeros 0 0

Normalized numbers 1-254 qualsevol

Infinites 255 0

Exp = 0 = 00000000 is reserved for zero rendering.

Exp = 255 = 11111111 is reserved for infinity representation.

Therefore, the values we have left, 1 ≤ Exp 254, are those that allow us to represent numbers
with the following exponents:-126 ≤ e ≤ 127, that is:
126 127
−2 ≤ x ≤2

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 10

2. Solved exercises

2.1 Numbering system in natural binary

ExercicE 1: How many bits would we need to encode the following values in natural binary?

A=120D, B=100D, C=–100D, D=150D.

Encode them in natural binary with n = 8 bits.

Solution:

With n bits we can represent numbers in the range in natural binary:

0 ≤ X < 2n,

C value is out of this range because it is negative and therefore will not be representable.

How to, B and D are positive encoded in natural binary with the following number of bits:

A) 0 ≤ 120< 2n,n = 7

B) 0 ≤ 100< 2n,n = 7

D) 0 ≤ 150< 2n,n = 8

Having A=120D=1111000B i B=100D=1100100B.

120 ÷ 2 100 ÷ 2 150 ÷ 2


0 60 ÷ 2 0 50 ÷ 2 0 75 ÷ 2
0 30 ÷ 2 0 25÷ 2 1 37 ÷ 2
0 15 ÷ 2 1 12÷ 2 1 18 ÷ 2
1 7÷2 0 6÷2 0 9÷2
1 3÷2 0 3÷2 1 4÷2
1 1 1 1 0 2÷2
0 1

Because it is asked us to encode it in natural binary, the end result is A=1111000B , B=1100100B
and D=10010110B

Exercicie 2: Perform operation A + B, where A = 120 D and B = 100D. Indicate whether the
result is representable in natural binary and 8 bits. Pass the result to decimal.

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 11

Solution:

When you add A + B The result is representable with 8 bits.

The result in decimal is:

X=11011100B= [27+26+24+23+22] = [128+64+16+8+4]= 220D.

The result coincides with the calculations made in decimal: 120 D+100D=220D.

2.2 Numeration system in Complement at 2

Exercise 3: Encode to C2 with n = 8 bits with the following values: A=120D, B=100D, C=–
100D, D=150D.

Solution:

With n=8 bits we can represent C2 numbers into the range:

–27 ≤ X < 27, or, –128 ≤ X < 128.

The D value is out of this range and therefore will not be representable.

As A and B are positive codified in natural binary.

We have A=120D=1111000B and B=100D=1100100B.

As they ask us to encode to 8 bits, the end result is A=01111000C2 and B=01100100C2. Notar
els bits de signe positius. Notice the bits of positive sign

As for C= –100D, for being negative, it is necessary to use the formula of the C2:

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 12

–100D=C2(100D)=C1(01100100B)+1=10011011+1=10011100C2 (bit of negative sign)

Exercice 4: Perform operation A + B. Indicate whether the result is correct at the sign bit
view. Passing the result to decimal

Solution:

When you add A + B The result is incorrect because the resulting sign bit indicates A negative
number even though the two totals were positive. There have been, then, overflow.

The result in decimal is:

X=11011100B=–C2(11011100B)= –[00100011+1] = – 00100100C2=


= –[25+22]= –[32+4]= –36D.

The result should have been 120D + 100D = 220D But as we have seen in the previous year this
number is left out of the representation range with 8 bits and for that the overflow occurred.

Exercice 5: Do the operation A – B.

Indicate whether the result is correct at the sign bit view. Passing the result to decimal

Solution:

For the rest A – B What we will do is A + C since C = – B. As the representation is in 8 bits,


the first "1" of the result is discarded and we have a positive sign result.

As the result is positive, to move to decimal enough to do:

X=00010100C2=[24+22]= [16+4]= 20D.

This result is correct as the sum operation with different signs does not give problems. Also, it
can be seen that the result coincides with what is obtained when doing the operation in decimal,
A – B = A + C = 120D – 100D = 20D.

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 13

2.3 Floating point numbering system

Exercice 6:Given the next number encoded in floating point, indicate its value in decimal.

11000010 01001111 00000000 00000000

Solution:

The floating point format is as follows:

1 1000010010011110000000000000000

In the sign bit, s = 1 view, we see that it's a negative number.

From the field of exponent we see that Exp=10000100=27+22+1=128+4=132.

Therefore, the number exponent is e=Exp-127=132-127=5.

The binary number expressed in scientific notation is:

X = -1,1001111×25

Which is equivalent to:

X = -110011,11

Finally, the number in decimal is:

X = - [ 25+24+21+20+2-1+2-2]=-[51+0.75]=-51,75

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 14

3. Proposed exerrcices

You are asked to resolve the following exercises individually and take them to the SD1
problems session. The solutions must contain the necessary calculations and explanations. It is
important to emphasize the final response to each of the exercises (through a box, for example).
Pay attention to the quality of the presentation (this must be clear, clean and direct).

3.1 Numbering system in natural binary

Exercice 1. Convert the following number to natural binary: 388,0625D.

Exercice 2. Convert to decimal the following number: 1011101,0101B.

Exercice 3. Indicate which is the minimum number of bits to represent the following values in
natural binary: A = 2048 , B=0 , C = 63244 , D = -22

3.2 Numeration system with Complement at 2

Exercice 4. Get the natural binary of X = 197 D with n = 8 bits. Is it used as coding in C 2 with n
= 8 bits? Justify the answer. If not, indicate how it could be solved.

In the following exercises, consider the following two encoded numbers in C 2

X = 10010101

Y = 01110111

Exercice 5. It is asked:

a) Convert X and Y numbers to decimal

b) Calculate X + Y and X-Y in decimal.

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC


EP1: Numeration systems 15

Exercice 6. It is asked:

a) perform the operation X + Y in binary.

b) In view of the sign bit indicate if there has been overflow and justify the response.

c) Convert the result to decimal and compare the result with the obtained in the exercise 5.

Exercice 7. It is asked:

a) To perform the operation X-Y by making a sum in binary.

b) In view of the sign bit indicate if there has been overflow and justify the response.

c) Convert the result to decimal and compare the result with the obtained in the exercise 5.

3.3 Floating point numbering system

Exercice 8. What is the largest positive number representable in a single precision floating point
(32 bits)? Putting value in binary and scientific notation.

Exercice 9. Encode the number -584, 125D by floating point.

Exercice 10. Given the next number encoded in floating point, obtain its representation in
decimal

01000101 11010000 00000000 00000000

INFORMATICS ENGINERING * Previous Study 1* ESAII - FNB * UPC

You might also like