0% found this document useful (0 votes)
68 views23 pages

Discrete Math Lecture #05 (2020) PDF

- The document discusses number bases and converting between different number systems. It explains that decimal, binary, octal, and hexadecimal are common number bases. - Converting a number from one base to another involves expressing it as a sum of place values times the base to different powers. Converting to decimal involves multiplication, while converting from decimal involves repeated division and collecting remainders. - Floating point numbers require separating the integer and fractional parts before converting. Fractions in decimal are converted to binary by repeatedly multiplying by the new base and collecting coefficients rather than dividing.

Uploaded by

Hitham
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)
68 views23 pages

Discrete Math Lecture #05 (2020) PDF

- The document discusses number bases and converting between different number systems. It explains that decimal, binary, octal, and hexadecimal are common number bases. - Converting a number from one base to another involves expressing it as a sum of place values times the base to different powers. Converting to decimal involves multiplication, while converting from decimal involves repeated division and collecting remainders. - Floating point numbers require separating the integer and fractional parts before converting. Fractions in decimal are converted to binary by repeatedly multiplying by the new base and collecting coefficients rather than dividing.

Uploaded by

Hitham
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/ 23

Discrete MATH

ITCS 1313
2020 / 2021
NUMBER THEORY
Lecture #05
Discrete MATH by Yahya AMER

Outlines
◼ Number Properties

◼ Common Number Bases

◼ Any Number System To Decimal & Vise Versa

◼ Binary Numbers To Any Number System & Vise Versa

◼ Octal To Hexadecimal And Vise Versa:-

◼ Any Number System to Any Number System


Discrete MATH by Yahya AMER

Number Properties
(7392.86)10 (10011.11)2 (2065.64)7 (2031.21)4
In number system we all familiar with decimal numbers such as (8765)
but the question is that what do we mean by saying (7392)?

(7392) is really means: -


7000 + 300 + 90 + 2
7  1000 + 3  100 + 9  10 + 21
7  103 + 3  102 + 9  101 + 2  100
Discrete MATH by Yahya AMER

Also (901223)10 means:-


9  105 + 0  104 + 1  103 + 2  102 + 2  101 + 3  100

These are the coefficients,


which are (901223) This is the base or the radix,
which is 10
Thus when we write the decimal number (901223), we only write
the coefficients. notice that the coefficients are always between
(0 and 9) or between (0 and (the base -1)).
Thus the following are wrong numbers

(1002111)2 (20754)7 (20351)4 Why???


wrong wrong wrong
Discrete MATH by Yahya AMER

Ok, now we understood what (9876)10 means, but how about the decimal
number (9876.32)10
(9876.32)10 really ,means:-

9  103 + 8  102 + 7  101 + 6  100 + 3  10-1 + 2  10-2

Thus in general, a number expressed in a base or radix r system has coefficients


aj (from 0 to (r –1 )) multiplied by power or r.
Here is the general formula:-

an  r n + an-1  r n-1 +….+ a2  r 2 + a1  r 1 + a0  r 0 + a-1  r -1 +…+ a-m  r -m

Now lets follow the general formula above to see what the number
(4021.2)5 means. It means
4  53 + 0  52 + 2  51 + 1  50 + 2  5-1

Notice again the coefficients are digits between (0 and 4) and the base is 5.
Discrete MATH by Yahya AMER
When we say the binary number (11011)2 we mean:-

1  24 + 1  23 + 0  22 + 1  21 + 1  20

These are the coefficients, which This is the base or the radix,
are (11011) which is 2

Thus when we write the binary number (11011), we only write the coefficients.

And (11011.101)2 really ,means:-

1  24 + 1  23 + 0  22 + 1  21 + 1  20 + 1  2-1 + 0  2-2 + 1  2-3


Discrete MATH by Yahya AMER

COMMON NUMBER BASES


As we know the DECIMAL number system is of base 10. So the (9876.32)10 means

9  103 + 8  102 + 7  101 + 6  100 + 3  10-1 + 2  10-2

As we know the BINARY number system is of base 2. So the (11011.101)2 means

1  24 + 1  23 + 0  22 + 1  21 + 1  20 + 1  2-1 + 0  2-2 + 1  2-3

As we know the OCTAL number system is of base 8. So the (127.4)8 means

1  82 + 2  81 + 7  80 + 4  8-1

Again the HEXADECIMAL number system is of base 16. Thus (B65F)16 means

B  163 + 6  162 + 5  161 + F  160


Discrete MATH by Yahya AMER

Any Number system to Decimal :-


We convert any number system to Decimal system using General Formula.
So when we make the calculations as the following using the general
formula we got the equivalent decimal number…

(9876.3)10 = 9  103 + 8  102 + 7  101 + 6  100 + 3  10-1 = (9876.3)10

(4021.2)5 = 4  53 + 0  52 + 2  51 + 1  50 + 2  5-1 = (511.4)10

(127.4)8 = 1  82 + 2  81 + 7  80 + 4  8-1 = (87.5)10

(B65F)16 = B  163 + 6  162 + 5  161 + F  160 = (46687)10

(11011)2 = 1  24 + 1  23 + 0  22 + 1  21 + 1  20 = (27)10
Discrete MATH by Yahya AMER

Decimal To any Number system:-


Now the next topic is how to convert a Decimal Number to any number
system. This conversion done by repeated division, which works as
the following. We divide the decimal number and all successive
quotients by r (base) and accumulating the remainders.
Lets have some examples to illustrate the idea.
Example : Convert (153 )10 to Octal
Quotients Remainder

153 / 8 = 19 + 1

19 / 8 = 2 + 3

2 /8 = 0 + 2 = (2 3 1)8
Discrete MATH by Yahya AMER

- Convert the decimal number (41 )10 to binary number.

Quotients Remainder

41 / 2 = 20 + 1

20 / 2 = 10 + 0

10 / 2 = 5 + 0
= (1. 0 .1.0 0 1)2
5/2 = 2 + .1

2/2 = 1 + .0

1/2 = 0 + .1
Discrete MATH by Yahya AMER

- Convert (230 )10 to a number of base 5

Quotients + Remainder

230 / 5 = 46 + 0
= (1 4 1 0)5
46 / 5 = 9 + 1

9/5 = 1 + 4

1/5 = 0 + 1
Discrete MATH by Yahya AMER

Convert (2291)10 to a number of base 16 (Hexadecimal number)


dec Hex

Quotients + Remainder 0 0
1 1

2291 / 16 = 143 + 3 2 2

= (8 (15) 3 )16 3 3

143 / 16 = 8 + 15 4 4
5 5
= (8 F 3 )16 6 6
8 / 16 = 0 + 8
7 7
8 8
9 9
- Notice that we always divide by the base of the number 10 A

we want to convert to. Also the remainder cannot be 11 B


12 C
greater than the base of the number we want to convert 13 D

to. We stop dividing until the Quotient become 0. 14 E


15 F
Discrete MATH by Yahya AMER
Now the question is how do we convert a floating-point decimal number like
(41.25)10 to any number system
Lets assume that we want to convert this number (41.25)10 to binary number. the
steps are the following:-
1) we separate the number since (41.32 )10 = (41 )10 + (0.25 )10
2) we find the binary number of (41 )10
3) we find the binary number of (0.25 )10
4) we combine the two binary numbers together.
Since (0.25 )10 is a fraction and we want to convert it to binary number, we do
not divide by the base of the binary numbers as we did before. We multiply by
the base as shown bellow:-

Integer + fraction coefficient

0.25 X 2 = 0 + 0.5 0
0.5 X 2 = 1 + 0.0 1
Therefore, (0.25)10 = (0.01)2 we combine both binary numbers.
So (41.25 )10 = (101001)2 + (0.01)2 = (101001.01)2
Discrete MATH by Yahya AMER

Lets do another example :-


Convert (0.6875)10 to binary number.
Integer + fraction coefficient

0.6875 X 2 = 1 + 0.3750 1
0.375 X 2 = 0 + 0.75 0
0.75 X 2 = 1 + 0.5 1
0.5 X 2 = 1 + 0.0 1

Therefore, (0.6875)10 = (0.1011)2

Notice that we read the result of the coefficients from top to the
bottom. Notice also we always multiply by the base of the number
system we want to convert to. Also when we get all 0 in the fraction
we can stop. However what if we could not get 0 in the fraction.??
Discrete MATH by Yahya AMER

Lets answer using an example:- Convert (0.33)10 to binary


Integer + fraction coefficient

0.33 X 2 = 0 + 0.66 0
0.66 X 2 = 1 + 0.32 1
0.32 X 2 = 0 + 0.64 0
0.64 X 2 = 1 + 0.28 1
0.28 X 2 = 0 + 0.56 0
0.56 X 2 = 1 + 0.12 1
0.12 X 2 = 0 + 0.24 0
Notice here that the fraction does not seem to be going to 0. so we can stop any time
depending on the accuracy of the fraction we want.
So the binary value of (0.33)10 = (0.0101010…….)2
To get the idea more clear, the fraction (7/22) = (0.318) will do the job. But if we
want to be more accurate (7/22) = (0.318181818). and again if we want to be more
and more accurate (7/22) = (0.318181818181818181818181818…….).

Thus when we convert fraction number into binary, we can stop according
to the accuracy we want.
Discrete MATH by Yahya AMER

Binary Numbers To any number system:-


Now at this point we understood the conversion from any number system to
decimal number, also the conversion from any decimal number to any
number system.
We saw earlier the conversion ( binary  decimal)

Example: (11011)2 = 1  24 + 1  23 + 0  22 + 1  21 + 1  20 = (27)10

Example: (101011.101)2 = (43.625)10

Example: (41 )10 = (101001)2

Example: (0.6875)10 = (0.1011)2

Example: (0.33)10 = (0.0101010…….)2


Discrete MATH by Yahya AMER

Converting binary number to Octal number.


First notice that Octal number is of base 8 which is 23. That means 3 binary
digit can represent one Octal number. so to convert a binary number to an Octal
number we can group the binary number and each group has 3 binary digits. Then
we find the Octal value of each group and then combine them together.
let see an example:-
Convert (1101101101) 2 to Octal number.

First we divide (1101101101) 2 into groups of 3 digits from right to left as follows

(1101101101) 2 → (001 101 101 101 ) 2 NOT (110 110 110 1) 2

( 1 5 5 5 )8
Then we find the value of each group as shown above. Notice that we add 2 zeros to
left side of the 1 which does not change its value. It is a good habit to do like this.

Then we combine the values together. Thus (1101101101)2 = (1555)8


Discrete MATH by Yahya AMER

Lets do another example:


Convert (11101000111.1011) 2 to Octal

(11101000111.1011) 2 = (011 101 000 111 .101 100) 2

=( 3 5 0 7 . 5 4 )8

(11101000111.1011) 2 = (111 010 001 11 . 1 011) 2

=( 7 2 1 3 . 1 3 )8

Notice that when we grouped the fraction part we started from left to right. So when
we grouped the fraction (0.1011) 2, we grouped it as (101 100) 2 NOT (1 011) 2 which
would give us different value.
Notice also we added 00 to (1) to make it (100) which is group of 3. thus
(0.1011 ) → (101 1) → (5 1)8 is WRONG. And the right thing is to add 00 to (1) to
make group of 3 digits. So the correct answer is (101100) 2 = (5 4)8
Discrete MATH by Yahya AMER

Convert from binary to Hexadecimal


If we want to convert from binary to Hexadecimal, we follow the same procedures we
did with the Octal except we group the binary number into 4 digits not 3 digits
because the Hexadecimal number system is of base 16 which is 24.
Lets see an example :-

Convert (10110001101011.111101)2 to Hexadecimal

(10110001101011.111101)2 → (0010 1100 0110 1011 . 1111 0100)


( 2 C 6 B . F 4 ) 16

(10110001101011.111101)2 = ( 2 C 6 B . F 4 ) 16
Discrete MATH by Yahya AMER

Convert from binary to other number systems


Ok, so far we are done with converting from binary to Decimal, Octal and
Hexadecimal. Now the question is how do we convert a binary number to different
number system. For example how do we convert (1110010)2 to number system of
base 5. Well, the answer is that it is hard to do it as we did with Octal and
Hexadecimal Numbers. So to convert this binary number to a number system of base
5, we first convert the binary number to Decimal and then from Decimal to the
number system of base 5.
Example : convert (1110010)2 to (……)5
First , we convert to decimal (1110010)2 = (114)10
Then from decimal to base 5 : (114)10 = (422)5
So (1110010)2 = (422)5
Discrete MATH by Yahya AMER

Converting any number system to binary


We saw earlier the conversion from decimal to binary. So lets see how to convert
from Octal to binary

Example: Convert (56732) 8 to binary.


(56732) 8 → ( 5 6 7 3 2 )8
( 101 110 111 011 010 ) 2 → (101110111011010) 2
Example : Convert (56.32) 8 to binary

(56.32) 8 → ( 5 6 . 3 2 )8
( 101 110 . 011 010 ) 2 → (101110.011010) 2
Example : Convert (306.D)16 to binary
(306.D) 16 → ( 3 0 6 . D ) 16
( 011 000 110 . 1101 ) 2 → (11000110.1101) 2
Example: Convert (234)5 to binary.
Since there is no systemic way to do , we first convert it to decimal then we
convert into binary.
First we convert it to Decimal →(234)5 = (69)10
Then we convert the decimal number to binary → (69)10 = (1000101)2
So (234)5 = (1000101)2
Discrete MATH by Yahya AMER
Octal To Hexadecimal and vise versa:-
The easiest way to do it is first to convert from Octal to binary and then convert the binary back
to Hexadecimal. For example: Convert (37345.25)8 to Hexadecimal.
(37345.25)8 → ( 3 7 3 4 5 . 2 5 )8
( 011 111 011 100 101 . 010 101 )2
(11111011100101.010101)2 = (0011 1110 1110 0101 . 0101 0100 )2
= ( 3 14 14 5 . 5 4 )16
= ( 3 E E 5 . 5 4 )16
So (37345.25)8 = (3EE5.54)16

Now to convert from Hexadecimal to Octal we follow the same procedure by first
converting the hexadecimal number to binary and then from binary to Octal.
Example : Convert (3EE5.54)16 to Octal
(3EE5.54)16 =( 3 E E 5 . 5 4 )16
= (0011 1110 1110 0101 . 0101 0100 )2
= (0 0 1 1 1 1 1 0 1 1 1 0 0 1 0 1 . 0 1 0 1 0 1 0 0 )2
= (0 011 111 011 100 101 . 010 101 000 )2
= (0 3 7 3 4 5 . 2 5 0 )8
Discrete MATH by Yahya AMER

You might also like