0:00

[MUSIC]

In this lesson and in the following one, some prior knowledge

necessarily to follow our course on digital systems will be presented.

This first lesson is about binary numeration system.

Computers receive, store, proces,

transmit data of different types,

for example, numbers, characterss, sounds, or pictures.

0:43

The common point is that all those data must be encoded using zeroes and ones,

and computer technology is based on

electronic circuits that process this kind of information,

that is to say that they process vectors of zeroes and

ones, the so-called binary encoding system.

Among the data processed by computers, an essential type is constituted

by numbers. How can we represent numbers and

perform arithmetic operations with only two digits, 0 and 1?

We already know the decimal system, and

we are going to define the binary and the hexadecimal systems.

First, some comments about

a traditional numeration system: the decimal system.

Decimal system uses ten digits: 0, 1, 2 and so on up to 9,

and it is a positional system.

That means that a weight is associated to every digit position.

So, the position of the digit within the number is relevant.

An example, when we write 653,

what we mean is: 6 times 10 to the power 2,

plus 5 times 10 to the power 1, plus 3 times 10 to the power 0.

Six hundredths, five tenths, and three units.

Then, we can do the same, but with 10 replaced by 2,

so that in binary there are two digits instead of 10,

called binary digit or, in short, bits.

It is a position system and

to the positions of the bits are associated weights that are

powers of 2 instead of powers of 10.

Let us see an example: the binary number 1101 represents

1 times 2 to the power of 3, that is to say 8,

plus 1 times 2 to the power 4,

plus 0 times 2 to the power 1, plus 1 times 2 to the power 0.

So that this is 8 plus 4 plus 1 equal to 13.

So that this binary vector is the binary representation of decimal 13.

Now, an exercise:

compute the decimal representation of this binary number.

The solution is this one.

Here, there are six bits that correspond to weights

2 to the 5, that is to say 32.

2 the 4: 16,

2 to the 3: 8,

square 2: 4.

2 and 1,

and the represented number is 32 plus 8 plus 1,

4:20

that is to say, 41.

Now, some comments about the range of representable numbers.

With n bits we can represent all natural numbers from 0 to 2 to the n minus 1.

There are exactly 2 to the n combinations of 0's and 1's in an n bit vector.

Here is an example with n equal to 4:

There are 16 combinations of 4 bits and in this table we see

all the combinations from 0000 up to 1111,

that correspond to decimal numbers from 0 to 15.

Let us see more examples:

with 3 bits we can represent all numbers from 0 to 7.

With 4 bits, all naturals from 0 to 15.

With 5 bits, all naturals from 0 to 31,

and with 6 bits, all natural numbers from 0 to 63.

Conversely, how many bits do we need to represent some given natural number?

For example, to represent 48 we must look for

a value of n such that 48 is smaller than 2 to the n,

but greater than or equal to 2 to the n minus 1.

In this case, the solution is 6, because

actually, 48 is greater than or equal to 32,

but is smaller than 64.

And you can check that number 48

can be represented in this form.

6:25

Actually, this is 32.

The weight corresponding to this bit is 32,

and the weight corresponding to this one is 16.

So that the represented number is 48.

Sometimes, instead of base 2 system,

a base 2 to the 4 that is 16

system is used,

the so-called hexadecimal system.

Then, there are 16 digits,

7:01

from 0 to 15 but, as regards digits 10,11,12,13,14,15,

letters are used instead of digits.

It's a positional system.

As an example, this hexadecimal number is

3 times 16 to the 3,

8:45

A, that is to say 10, in binary is 1010,

and 3 in binary is 0011.

So that the representation of hexadecimal 3 A 9

is binary 0011 1010 1001.

Conversely, to translate a binary

representation to a hexadecimal representation,

we partition the binary number into 4-bit vectors from right to left.

In this case, first group, second one,

the third one and the fourth one,

and then, we replace those vectors by hexadecimal digits.

For example, 0101 is equal to 5.

1010 is 10,

and, in hexadecimal we write it as A.

1011 is equal to eleven.

We represent eleven,

and in hexadecimal, we write it as B,

and finally 0100 is equal to 4.

So, the conversion from binary to hexadecimal is straightforward.

An exercise: compute the hexadecimal representation of this binary number,

and then (second part of the exercise)

compute the binary representation of this hexadecimal number.

11:21

F by 1111 and 5 by 0101,

and, we get the binary representation of this hexadecimal number.

The conversion of decimal to binary is not as simple

as from hexadecimal to binary.

The conversion algorithm consists of a sequence of divisions by 2.

Let us see an example.

We want to represent 18 in binary.

Then, the sequence of divisions is as follows:

18 divided by 2 is equal to 9 with the remainder equal to 0;

9 divided by 2 is equal to 4 with the remainder equal to 1;

4 divided by 2 is equal to 2 with the remainder equal to 0,

2 divided by 2 is equal to 1

with remainder equal to 0,

and the computation ends when the obtained quotient is equal to 1,

as in this case.

Then, the result of the conversion is this latest quotient

12:46

and the sequence of remainders in reverse order,

that is to say 0010,

and, you can check that this binary vector

represents 16 plus 2,

that is to say 18.

Exercise: write number 43 in binary.

Here is the solution:

43 divided by 2 is equal to 21,

and, the remainder is equal to 1.

21 divided by 2 is equal to 10, and the remainder is equal to 1.

10 divided by 2 is equal to 5, remainder equal to 0.

5 divided by 2 is equal to 2,

remainder equal to 1,

and finally, 2 divided by 2 is equal to 1, remainder equal to 0,

and, the result of the conversion is this 1

14:24

This is 43.

It remains to see how sums and differences are performed in binary.

Actually, it is just an adaptation of the classical decimal

addition and difference adapted to the binary system.

When we add up two bits, they are four possibilities:

0 plus 0 is 0:

0 plus 1 and 1 plus 0 is equal to 1;

and 1 plus 1 is equal to 2

that, in binary, can be written

14:59

under this form, so that the current step bit is 0

and the carry to the next step is 1.

An example: if we must compute A plus B, then

1 plus 1 is 2 so that the bit of this step is 0

and there is a carry equal to 1; 1 plus 1 equal to 0, carry 1;

1 plus 1 plus 1 is equal to 3,

that is to say the bit of this step is 1, and there is a carry 1;

1 plus 0 plus 0, 1,

carry equal to 0;

0 plus 1, 1, carry 0; 1 plus 0, 1, carry 0;

0 plus 1, 1, carry equal to 0,

and 1 plus 0 equal to 1, and this is the result.

When computing the difference between two bits, there are also 4 possibilities:

0 minus 0 is 0, 1 minus 0 is 1, 1 minus 1 is 0,

and 0 minus 1 is equal to -1

that can be written as minus 2 plus 1.

So, the current step bit is equal to 1,

but there is a borrow from the next step equal to 1.

An example:: if we compute a minus b, then 1 minus 1 is 0;

16:41

and there is a below to the next step equal to 1;

0 minus 0 minus 1, once again it's -1;

0 minus 1 minus 1 minus 1 is -2,

so 0 and borrow equal to 1; 1 minus 1 is 0, there is no borrow;

0 minus 1, 1 with borrow equal to 1,

and finally, 1 minus 1, 0.

So, the result is this one.

Now, an exercise: compute A plus B, and A minus B.

Solution. First A plus B:

1 plus 1, 0, carry 1;

0 plus 1 plus 1, 1, carry 1;

1 plus 0 plus 0, 1, carry 0;

0 plus 1 plus 0, 1, carry 0;

1 plus 1, 0, carry 1;

18:06

1 minus 1, equal to 0;

0 minus 0

0, borrow equal to 0;

0 minus 1, 1, borrow equal to 1,

and finally, 1 minus 1, 0.

And this is the result.

Summary:

we have seen that in computers

data are represented with 0's and 1's.

The binary numeration system has been defined,

as well as the the hexadecimal system.

The range of representable

numbers have been computed.

Conversion methods between numeration systems have been seen,

and finally addition and

difference algorithms for binary numbers have been described.