Sie sind auf Seite 1von 28

ELE 574 Applications of Microcontrollers and PLCs

Dr. Shadi A. Alboon Electronics Engineering Department Hijjawi Faculty for Engineering Technology Yarmouk University, Irbid 21163, Jordan shboon@yu.edu.jo

Number Systems Binary and Hexadecimal

How do Computers Represent Digits?


Binary digits (0 and 1) are used instead of decimal digits Using electric voltage High = 1 Used in processors and digital circuits Unused High voltage = 1, Low voltage = 0 Low = 0 Using electric charge Used in memory cells Charged memory cell = 1, discharged memory cell = 0 Using magnetic field Used in magnetic disks, magnetic polarity indicates 1 or 0 Using light Used in optical disks, surface pit indicates 1 or 0
ELE 574 Dr. Shadi Alboon

Voltage Level

Popular Number Systems


Binary Number System: Radix = 2 Only two digit values: 0 and 1 Numbers are represented as 0s and 1s Octal Number System: Radix = 8 Eight digit values: 0, 1, 2, , 7 Decimal Number System: Radix = 10 Ten digit values: 0, 1, 2, , 9 Hexadecimal Number Systems: Radix = 16 Sixteen digit values: 0, 1, 2, , 9, A, B, , F A = 10, B = 11, , F = 15 Octal and Hexadecimal numbers can be converted easily to Binary and vice versa
ELE 574 Dr. Shadi Alboon 4

Numbers systems
Decimal Radix 10 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
ELE 574

Binary Radix 2 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

Octal Radix 8 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17

Hex Radix 16 0 1 2 3 4 5 6 7 8 9 A B C D E F
5

Dr. Shadi Alboon

Decimal Number System


Ten Digits, so it is said to be base 10 0,1, 2, 3, 4, 5, 6, 7, 8, 9 Ten fingers Each position in the decimal system represents 10n 4567 = 7 X 100 + 6 X 101 + 5 X 102 + 4 X 103
Dr. Shadi Alboon

ELE 574

Binary
The word binary is derived from the Latin root bini (or two by two). Binary number has base 2, we use only two symbols, Each digit is one of two numbers: 0 and 1 0,1,10,11,100,101 etc Each digit is called a bit Eight binary bits make a byte Each position in a binary number represents 2n Thus 10101= 1 X 20 + 0 X 21 + 1 X 22 +0 X 23 + 1 X 24
ELE 574 Dr. Shadi Alboon 7

Binary
Integers

ELE 574

Dr. Shadi Alboon

Binary
Example
The following shows that the number (11001 11001) )2 in binary is the same as 25 in decimal decimal. . The subscript 2 shows that the base is 2.

The equivalent decimal number is N = 16 + 8 + 0 + 0 + 1 = 25. 25.


ELE 574 Dr. Shadi Alboon

Binary
Real

Example The following shows that the number (101 101. .11 11) )2 in binary is equal to the number 5.75 in decimal decimal. .

ELE 574

Dr. Shadi Alboon

10

Octal
The word octal is derived from the Latin root octo (eight). Octal numbers has base 8 We use eight symbols to represent a number. Each digit is a number from 0 to 7 Each digit represents 3 binary bits Was used in early computing, but was replaced by hexadecimal
ELE 574 Dr. Shadi Alboon 11

Octal
Integers

ELE 574

Dr. Shadi Alboon

12

Octal
Example The following shows that the number (1256) 1256)8 in octal is the same as 686 in decimal decimal. .

Note that the decimal number is N = 512 + 128 + 40 + 6 = 686. 686 .


ELE 574 Dr. Shadi Alboon

13

Hexadecimal
The word hexadecimal is derived from the Greek root hex (six) and the Latin root decem (ten). Hexadecimal numbers has base 16 16 DIGITS 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Note that the symbols A, B, C, D, E, F are equivalent to 10, 11, 12, 13, 14, and 15 respectively. Numbers go 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1A, 1B, 1C, 1D, 1E, 1F, 20 etc
ELE 574 Dr. Shadi Alboon 14

Hexadecimal
Integers

ELE 574

Dr. Shadi Alboon

15

Hexadecimal
Example The following shows that the number hexadecimal is equivalent to 686 in decimal decimal. . (2AE) AE)16 16 in

The equivalent decimal number is N = 512 + 160 + 14 = 686. 686 .


ELE 574 Dr. Shadi Alboon

16

Summary of the four systems


The table below shows a summary of the four positional number systems discussed in this chapter.

ELE 574

Dr. Shadi Alboon

17

Decimal Value of Binary Numbers



7 6

Each bit represents a power of 2 Every binary number is a sum of powers of 2 Decimal Value = (dn-1 2n-1) + ... + (d1 21) + (d0 20) Binary (10011101)2 = 27 + 24 + 23 + 22 + 1 = 157
5 4 3 2 1 0

1
27

0
26

0
25

1
24

1
23

1
22

0
21

1
20

Some common powers of 2


ELE 574 Dr. Shadi Alboon

18

Convert Decimal to Binary


Repeatedly divide the decimal integer by 2 Each remainder is a binary digit in the translated value Example: Convert 3710 to Binary

least significant bit

37 = (100101)2
most significant bit stop when quotient is zero
ELE 574 Dr. Shadi Alboon 19

Convert 47 in Decimal to Binary


47 / 2 = 23 rem 1 23 / 2 = 11 rem 1 11 / 2 = 5 rem 1 5 / 2 = 2 rem 1 2 / 2 = 1 rem 0 1 / 2 = 0 rem 1

Hence 47 in decimal format equals 101111 in binary format.


ELE 574 Dr. Shadi Alboon 20

Convert Binary to Decimal

10111

1 X 16

0X8

1x4

1x2

1X1

16 + 0 + 4 + 2 + 1 = 23
ELE 574 Dr. Shadi Alboon 21

Convert Binary to Hexadecimal


Any combination of 4 bin0111ary digits together will always represent the decimal numbers 0 to 15. Divide the binary number into groups of 4, from right to left. To convert 10001101 binary to hexadecimal, 1101 equals 13, which is D and 1000 equals 8. So 10001101 in binary equals 8D in hexadecimal. If there are less than 4 digits on the left add zeros to the left. For example 100111, is divided into and 0010 and 0010 hence equals 27 in hexadecimal.
ELE 574 Dr. Shadi Alboon

22

Convert Hexadecimal to Binary


For example 2D4F 2=0010 D=1101 4=0100 F=1111 Then 2D4F=10110101001111

ELE 574

Dr. Shadi Alboon

23

Converting Decimal to Hexadecimal


Best way is to go decimal to binary and then binary to hexadecimal. OR Repeatedly divide the decimal integer by 16 Each remainder is a hex digit in the translated value
Example: convert 422 to hexadecimal least significant digit

most significant digit

422 = (1A6)16
ELE 574

stop when quotient is zero


Dr. Shadi Alboon

To convert decimal to octal divide by 8 instead of 16


24

Important Properties
How many possible digits can we have in Radix r ? r digits: 0 to r 1 What is the result of adding 1 to the largest digit in Radix r? Since digit r is not represented, result is (10)r in Radix r Examples: 12 + 1 = (10)2 78 + 1 = (10)8 910 + 1 = (10)10 F16 + 1 = (10)16 What is the largest value using 3 digits in Radix r? In binary: (111)2 = 23 1 In octal: (777)8 = 83 1 In Radix r: In decimal: (999)10 = 103 1 largest value = r3 1
ELE 574 Dr. Shadi Alboon 25

Important Properties contd


How many possible values can be represented Using n binary digits? 2n values: 0 to 2n 1 Using n octal digits Using n decimal digits? Using n hexadecimal digits Using n digits in Radix r ?
ELE 574

8n values: 0 to 8n 1 10n values: 0 to 10n 1 16n values: 0 to 16n 1

rn values: 0 to rn 1
26

Dr. Shadi Alboon

Representing Fractions
A number Nr in radix r can also have a fraction part: Nr = dn-1dn-2 d1d0 . d-1 d-2 d-m+1 d-m 0 di < r Integer Part Fraction Part Radix Point The number Nr represents the value: Nr = dn-1 rn-1 + + d1 r + d0 +

(Integer Part) (Fraction Part)

d-1 r -1 + d-2 r -2 + d-m r m


i = n-1 j = -1

Nr =
ELE 574

di ri
i=0

dj rj
j = -m
Dr. Shadi Alboon 27

Examples of Numbers with Fractions


(2409.87)10 (1101.1001)2 (703.64)8 (A1F.8)16 (423.1)5 (263.5)6
ELE 574

= 2103 + 4102 + 9 + 810-1 + 710-2 = 23 + 22 + 20 + 2-1 + 2-4 = 13.5625 = 782 + 3 + 68-1 + 48-2 = 451.8125 = 10162 + 16 + 15 + 816-1 = 2591.5 = 452 + 25 + 3 + 5-1 = 113.2 Digit 6 is NOT allowed in radix 6
Dr. Shadi Alboon 28

Das könnte Ihnen auch gefallen