Professional Documents
Culture Documents
Discrete Math Lecture 06 PDF
Discrete Math Lecture 06 PDF
Mathematics
Number Theory
Outlines
Number System
Signed Numbers
Divisibility & Modular Arithmetic
Primes and GCD
Number System
Converting From Any Number System To Decimal
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:-
Now lets follow the general formula above to see what the number
(4021.2)5 means. It means
Again the HEXADECIMAL number system is of base 16. Thus (B65F)16 means
Now , here is a question for you….??? When we make the calculations as the following using
3X 52 + 2X 51 + 5X 50 = 3X 25 + 2X5 + 5 X 1 = (90)10
Now the next topic is how to convert a Decimal Number to any number
system…
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
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
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
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
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:-
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..
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.
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??
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
(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:-
(56732) 8 → ( 5 6 7 3 2 )8
( 101 110 111 011 010 ) 2 → (101110111011010) 2
(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.
The easiest way to do it is first to convert from Octal to binary and then convert the
binary back to Hexadecimal.
(76345.45)8 → ( 7 6 3 4 5 . 2 5 )8
( 111 110 011 100 101 . 010 101 )2
→ (11111011100101.010101)2