number system

advertisement
Lecture 1:Number systems
Lecturer: Noor Kadhum
1.2 Number system
A number system defines how a number can be represented
using distinct symbols. A number can be represented differently in
different systems. For example, the two numbers (2A)16 and (52)8 both
refer to the same quantity, (42)10, but their representations are
different. There are 4 basic number systems:
Name
Base
essential symbols
Binary
2
[0,1]
Decimal
10
0,1,…,9
Octal
7
0,1,…,6
Hexadecimal
16
0,1,…,F
1.3 Important terms
Here are important terms in this lecture:
1-Symbols: it is the set of digits that used in the number system In the
lecture, we will use the character (S) to express this set.
2-Base (or radix): is the number of symbols used in the number
system. we will use the character (b) to express this number.
To distinguish among numbers of different bases, we enclose the
coefficient in parenthesis an write a subscript equal to the base used.
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
For example
(13)10 --> decimal.
(13)16 --> hexadecimal
(13)8 --> octal.
3-Weighs : There is a weight of each coefficient (‫ )مرتبة‬,it is the base (b)
of the system powered by i where i = 0 ,1,2,…,k-1 where k is the number
of the digits in the integral part and i=-1,-2,…,L where L is the number
of the digits in the fractional part .The greater the value of the weight
the more importance of his coefficient .
Examples:
a-4224 :
It comes from 4 thousand plus 2 hundred plus 2 tens plus 4 like this
(4000+200+20+4 = 4×1000+2×100+20+4=4×103+2×102×2×10+4)
b-309:
3*102+0*10+9
1.4 Decimal Systems
The word decimal is derived from the Latin root decem (ten). In
this system we use ten symbols so this system is said to be of base 10
(b = 10 ).
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
S={0,1,2,3,4,5,6,7,8,9}
Now,how can we represent the numbers in the decimal system?
We can represent decimal numbers using the following general formula:
Which is a series of coefficient .the weights in this system have the form
10i (based on the definition of weights previously explained).
Note that , each weight in the integral part of its value equal to value of
the previous weight multiplied by 10. For fractional part, every weight
value equal to the value of the previous weight divided by 10.
The value of any number could be written as the summation of the
coefficients Multiplied by the corresponding weights :
For example:
24.13= 2×10+4 . 1×10-1+3×10-2
1.5 Binary system
The coefficients in this system have two possible values: 0 or 1, i.e.:
S={0,1}
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
The binary number consist of coefficients, each coefficient is called bit.
The leftmost bit of a binary number is called the Most Significant Bit
(MSB) because it is
The owner of the highest weight, while the bit which is located in
the right most number is called the Least Significant Bit (LSB) because
it has less weight. Weights in this system is 2 raised to the power of
i(based on the definition of weights previously explained).
2k-1
…
4
2
1
+
0.5
0.25
…
2-L
Note that each weight in the integral part of its value equal to double
value of the previous weight(1 ,2,4,8,16,32,…). For fractional part, every
weight value equal to the value of the previous weight divided by 2
(0.5,0.25,0.125,0.0625,…).
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
If No.of coefficient (length of binary number) in the binary number =8
,we call it byte. So byte is the binary number that has 8 bit.
Generally, If we have n bit, we can form 2n binary combinations.
For example :
If n=1---> No. of binary combinations = 21 =2
And these two values either 1 or 0 because we have 1 bit in this case.
Another example:
Suppose you have 2 bit
No. of binary combinations = 22 =4
So, you have 2 bit and 2 values to use (0 and 1)
The first possibility is : both bit have the value of zero.
The second possibility is : both bit have the value of one.
The third possibility is : one of them has the value of zero and the other
one has the value of one.in this case:
Either we get 0 1 or 1 0.
To summarized the results :
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
First bit
Second bit
0
0
0
1
1
0
1
1
1.6 Octal number systems
The word octal is derived from the Latin root octo (eight). In this
system the base b = 8 and we use eight symbols to represent a number.
The set of symbols is:
S={0,1,2,3,4,5,6,7}
The octal numbers are used in machine language programming for
microcomputers.
1.7 Hexadecimal system:
The hexadecimal number system is said to be of base 16 because it
uses 16 symbols:
S={ 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
Where A to F correspond 10 to 15
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
1.8 Conversion between decimal and other systems
In this section we learn how to convert from decimal to
(binary,octal,hexa) and vise versa by solving some examples:
a- To convert number from any system to decimal we use Weights :
𝑘−1
𝑙
∑ 𝑠𝑖 𝑏 𝑖
.
∑ 𝑠−𝑗
𝑖=0
𝑏−𝑗
𝑗=1
From right to left
from left to right
<----------------------
---------------------->
Where : s--> coeffecients, b-->the base.
I--> the order number in the integral part, j --> the order number in the
fraction part.
k--> No. of orders in the integral part , L--> No. of orders in the
fraction part.
Examples:
1- Convert (23.17)8 to decimal system:
2
3
.
1
7
81
80
.
8-1
8-2
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
= (81 ×2) + (80× 3) . ( 8-1 ×1) + (8-2 ×7)
=
16
=
+
3
+ 0.125 + 0.4375
19. 2344
2-Convert (110101)2 to decimal system:
SoL:
1
1
0
1
0
1
25
24
23
22
21
20
= (25×1) + (24× 1 )+ (23 ×0) +( 22 ×1) + (21 ×0) + (20× 1)
= 32
+
16
+
0
+
4
+
0
+ 1
= 53
3- Convert (110.001)2 to decimal system:
1
1
0
.
0
0
1
22
21
20
.
2-1
2-2
2-3
= ( 22 ×1) + (21 ×1) + (20× 0) . ( 2-1 ×0) + (2-2 ×0) + (2-3× 1)
=
=
4
+
2
+ 0
+
0
+
0 + 0.125
6.125
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
4- Convert (2AF3)16 to Decimal system:
SoL :
2
2
A
10
F
15
3
3
163
162
161
160
= (163 ×2) + (162× 10) . (161 ×15) + (160×3)
=
8192
=
10995
+
2560
+ 240 + 3
Note that (A,B,C,D,E,F) are converted to (10,11,12,13,14,15) to
be used as coefficients.
Practice: try to convert a real value into decimal
system.
b- To convert number from decimal to any system ,use division for
integer part and multiplication for fractional part:
Examples:
1- Convert (1256)10 to Hexa system:
division
1256 ÷ 16
78 ÷ 16
4 ÷ 16
Result of
div.
78
4
0 (stop)
reminder
8
14
4
Order
(right to left)
2
1
0
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
∴ (1256)10 = 4E8
Take into account that if you have (10,11,12,13,14,15) in the
reminder,you should convert it to the equivalent hexa value:
10 --> A
13-->D
11--> B
14-->E
12-->C
15-->F
This is the reason why we write E instead of 14.
2-convert (19. 1875)10 to octal system:
SoL:
a- Integral part :
division
19 ÷ 8
2÷8
Result of
div.
2
0
reminder
3
2
Order
(right to left)
1
0
b-fraction part (0. 1875):
Multiplication
0. 2344 × 8
0. 8750 × 8
Result of
mul.
1.8750
7 (or 7.0)
Before
dot
1
7
Order
(left to right)
1
2
∴ (19. 1875)10 = (23.17)8
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
1.9 Conversion between binary and other systems
In this section we learn how to convert from binary to octal and hexa
by expalining some examples, conversion between binary and dicimal
is already shown in the previous section.
a- Conversion from any system to binary :
The idea here is how many bits are needed to represent the
number in the other system, for example,in the octal system each
number is represented by 3 bits as seen in the following table,
because the largest symbol (7) needs 3 bit (or b=8 -8 = 23 No.of
required bits is 3):
Table 1.1 : binary octal conversion
octal
0
binary 000
1
2
3
4
5
6
7
001
010
011
100
101
110
111
The same thing applies to the hexa system, the largest
number (F i.e. 15) is represented by 4 bits (or b=16 16 = 24
No.of
required bits is 4)., so each number is converted to the
equivalent 4-bits in the binary system, as if we were dealing with
a decimal number, Let's see the following example:
Table 1.2 binary-hexa conversion
Hexa
0
1
2
3
4
5
6
7
binary 0000 0001 0010 0011 0100 0101 0110 0111
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Hexa
8
9
Lecturer: Noor Kadhum
A
B
C
D
E
F
binary 1000 1001 1010 1011 1100 1101 1110 1111
1.10 Conversion from binary to other systems
This process is opposite to the process described in the previous
section. For octal system, this conversion can be done in two steps:
1. binary number is divided into groups consisting of 3 bits.For
the integer part,the groups configure begins from right to left
but for the fractional part ,we start from left to right.
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
2. Each group is converted to its equivalent of the decimal system
using table 1.1
Another example:
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
1.11 Summary
The table below shows the numbers from 1 to 15 represented by the of
the four numbering systems :
Note that the digits 0 to 7 have the same representation in the decimal,
octal and hexadecimal.
Babylon university - Sciences College For Women - Digital Logic – first class
Lecture 1:Number systems
Lecturer: Noor Kadhum
Question to think about:
How many number of systems that can be used?
Exercises:
1234567-
Represent (175)10 using (binary- octal-hexa) .
Give the equivilant binary number for(0.076)10.
Convert (38)10 to(
)2 and (
)8.
Convert(56)8 to (
)16.
Convert(1110.11)2 to (
)8 and(
)10.
Convert (0.12)10 to Hexa system.
The decimal (21.6) equal to( ) in the binary.
Report (‫ )يقدّم بعد اسبوعين كحد اقصى‬:
Write a report a bout Hexa - Octal conversion. Support your report with
examples.
Babylon university - Sciences College For Women - Digital Logic – first class
Download