Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Discrete

Mathematics

Number Theory
Outlines
 Number System
 Signed Numbers
 Divisibility & Modular Arithmetic
 Primes and GCD
Number System
 Converting From Any Number System To Decimal

 Converting From A Decimal Number To Any Number System

 Converting From Any Number To Binary

 Converting From A Binary Number To Any Number System

 Converting From Any Number To Octal

 Converting From An Octal Number To Any Number System

 Converting From Any Number To Hexadecimal

 Converting From A Hexadecimal Number To Any Number System


Decimal Numbers:-

In number system, lets start analyzing the decimal number system. We


all familiar with decimal numbers such as (8,765) or (901,223), but the
question is that what do we mean by saying (7,392) and we pronounce it
as 7 thousands plus 3 hundreds, plus 9 tens, plus 2 units.

(7,392) is really means: -


7 X 103 + 3X 102 + 9 X 101 + 2X 100
Also (901223) means:-

9 X 105 + 0X 104 + 1X 103 + 2X 102 + 2 X 101 + 3X 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 (901,223), we only write


the coefficients.
Ok, now we understood what (9,876) means, but how about the
decimal number (9,876.32)

(9,876.32) really ,means:-

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

As we know the decimal number system is of base or radix 10. but why?

To answer this, notice that the coefficients are always between (0 and 9)
or between (0 and (the base -1)). For example we cannot see a
coefficient greater than 9 in the decimal number system. Also these
coefficients are multiplied by powers of 10. Thus for these two reasons,
we say the decimal number system is of base or radix 10.
When we say the binary number (11011) we mean:-

1X24 + 1X23 + 0 X22 + 1X21 + 1X20

These are the coefficients, This is the base or the


which are (11011) radix, which is 2
Thus when we write the binary number (11011), we only write the coefficients.

And (11011.101) really ,means:-

1X24 + 1X23 + 0 X22 + 1X21 + 1X20 + 1 X2-1 + 0X2-2 + 1X2-3


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 X r n + an-1X r n-1 +…….+ a2Xr2 + a1Xr1 + a0Xr 0 + a-1Xr -1 +…+ a-mXr -m


The number (1254.3)10 is of
base 10 The number
(1254.3)12 is of base 12

Now lets follow the general formula above to see what the number
(4021.2)5 means. It means

4X53 + 0X52 + 2X51 + 1X50 + 2X5-1


Notice again the coefficients are digits between (0 and 4) and the base is 5.
As we know the OCTAL number system is of base 8. So the (127.4)8 means

1X82 + 2X81 + 7X80 + 4X8-1

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

BX162 + 6X162 + 5X161 + FX160

Now , here is a question for you….??? When we make the calculations as the following using

the general formula we got decimal number… why????

(4021.2)5 = 4X53 + 0X52 + 2X51 + 1X50 + 2X5-1 = (511.4)10

(127.4)8 = 1X82 + 2X81 + 7X80 + 4X8-1 = (87.5)10

(B65F)16 = BX162 + 6X162 + 5X161 + FX160 = (46,687)10

(11011)2 = 1X24 + 1X23 + 0 X22 + 1X21 + 1X20 = (27)10


So at this point we learned how to convert any number system to
decimal number. for example , to convert the number (325)4 to
decimal number we do the following :-

3X 52 + 2X 51 + 5X 50 = 3X 25 + 2X5 + 5 X 1 = (90)10

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.


- Convert the decimal number (41) 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
- Convert (153) to Octal

Quotients + Remainder

153 / 8 = 19 + 1

19 / 8 = 2 + 3
= (2 3 1)8
2/8 = 0 + 2

- Convert (230) to a number of base 5


- Convert (230) 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
- Convert (229) to a number of base 16 which is Hexadecimal number

Quotients + Remainder

229 / 16 = 14 + 5
= (E 5 )16
14 / 16 = 0 + 14

- Notice that we always divide by the base of the number we want to convert to.
- Also the remainder cannot be greater than the base of the number we want to
convert to.
- We stop dividing until the Quotient become 0.
Now the question is how do we convert a floating-point decimal number like (41.25) to
any number system

We deal with this decimal number as following:-


Lets assume that we want to convert this number (41.25) to binary number. the steps are the
following:-
1) we separate the number since (41.32) = (41) + (0.25)
2) we find the binary number of (41)
3) we find the binary number of (0.25)
4) we combine the two binary numbers together.

Since (0.25) 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) = (101001) + (0.01) = (101001.01)2
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.??
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 have 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.
Binary Numbers To any number system:-

Now at this point we understood the conversion from any number system to decimal
number, also from any decimal number to any number system.
We saw earlier the conversion from binary to decimal
How about converting binary number to Octal number. let see an example:-

Convert (1101101101) 2 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 from a binary number to an Octal number we
can group the binary number and each group has 3 binary digits.

Second we find the Octal value of each group and then combine them together.
Lets do the example to see how..

First we divide (1101101101) 2 into groups of 3 digits 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

Notice that when we group the binary digits we start from right to left. Now the question is
what if we grouped the same binary number from left to right??

So (1101101101) 2 → ( 110 110 110 1 ) 2


( 6 6 6 1 ) which is (6661)8 which is the wrong answer
what if we want to convert the binary number (10110.11011)2 to Octal ?
again we follow the same procedure by separating the whole binary
number as follows:-
(10110.11011)2 → (10110) 2 + (0.11011) 2
The we group each one as follows:- (10110) 2 → (010 110 ) 2 → (26)8
(0.11011) → (110 110) → (66)8 → (0.66)8
Thus (10110.11011)2 → (26)8 + (0.66)8 = (26.66)8

Notice that when we grouped the fraction part we started from left to right. So when
we grouped the fraction (0.11011) 2, we grouped it as (110 11) 2 NOT (11 011) 2
which would give us different value.
Notice also we added 0 to (11) to make it (110) which is group of 3. thus
(0.11011 )→ (110 11) → (6 3)6 is WRONG. And the right thing is to add 0 to (11)
to make group of 3 digits. So the right answer is (110 110) 2
Lets do another example: - Convert (11101000111.1) to Octal

(11101000111.1) 2 → (011 101 000 111 . 100)


(3 5 0 7 . 4 )8 = (3507.4)8

(11101000111.1) 2 → (011 101 000 111 . 1)


(3 5 0 7 . 1 )8 = (3507.1)8 IS WRONG.

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 any way:-

Convert (10110001101011.111101)2 to Hexadecimal

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


( 2 C 6 B . F 4

(10110001101011.111101)2 = (2C6B.F4) 16
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.

So (1110010)2 = (114)10
And (114)10 = (422)5
So (1110010)2 = (422)5
So now lets start with 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:-

Convert (56732) 8 to binary.

(56732) 8 → ( 5 6 7 3 2 )8
( 101 110 111 011 010 ) 2 → (101110111011010) 2

Convert (56.32) 8 to binary

(56.32) 8 → ( 5 6 . 3 2 )8
( 101 110 . 011 010) 2 → (101110.011010) 2
Convert (306.D)16 to binary
(306.D) 16 → ( 3 0 6 . D) 16
( 11 000 110 . 1101) 2 → (11000110.1101) 2
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

Octal To Hexadecimal and vise versa:-

Lets convert from Octal to Hexadecimal

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 (76345.45)8 to Hexadecimal.


Convert (76345.45)8 to Hexadecimal.

(76345.45)8 → ( 7 6 3 4 5 . 2 5 )8
( 111 110 011 100 101 . 010 101 )2
→ (11111011100101.010101)2

(11111011100101.010101)2→ ( 11 1110 1110 0101 . 0101 0100 )2


( 3 E E 5 . 5 4 )16
So (76345.45)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.

You might also like