EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal...

46
EX_01.1/46 Numeric Systems

Transcript of EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal...

Page 1: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.1/46

Numeric Systems

Page 2: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.2/46Overview

• Numeric systems – general,

• Binary numbers,

• Octal numbers,

• Hexadecimal system,

• Data units,

• ASCII code ,

• Negative number’s representation.

Page 3: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.3/46

• Numeric systems – general,

• Binary numbers,

• Octal numbers,

• Hexadecimal system,

• Data units,

• ASCII code,

• Negative number’s representation.

Page 4: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.4/46Numeric systems – General …

• A numeric system consists of an ordered set of symbols, called digits, with relations defined for addition, subtraction, multiplication, and division,

•† < ¿ < Ä < ¤ < Æ < § < ₣ < ‡ < † < ®

Example: §Ä‡†® + Æ®†® = §‡‡†® ,

• The problem is that we use in different systems the very same symbols ,

• The base, of a number system, is the total number of digits allowed in the number system.

Page 5: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.5/46Numeric systems – General (Cont’d) …

• The most common number systems used in digital system design and computer programming are binary, decimal, hexadecimal and octal ,

• Computer’s information is coded in the shape of on or off bits; (1 and 0) ,

• this way of codifying takes us to the necessity of knowing the positional calculation which will allow us to express a number in any base where we need it.

Page 6: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.6/46Numeric systems – General (Cont’d) …

•  It is possible to represent a determined number in any base through the following formula:

• Where: n is the position of the digit beginning from right (position 0) to left and numbering from zero. D is the digit on which we operate and B is the used numeric base.

0

*n

nn BD

Page 7: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.7/46Numeric systems – General (Cont’d)

• Example of Positional Number System:173410 = 1*103 + 7*1002 + 3*101 + 4*10 ,

= 1*1000 + 7*100 + 3*10 + 4*1 ,

• Here 10 is the base, or radix, of the number system ,

• The value of the number is the sum of each digit multiplied by the corresponding power of the radix.

Page 8: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.8/46

• Numeric systems – general,

• Binary numbers,

• Octal numbers,

• Hexadecimal system,

• Data units,

• ASCII code,

• Negative number’s representation.

Page 9: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.9/46Binary Numbers …

• Digital systems are usually constructed using two-state devices that are either in an off state or an on state,

• Therefore, the binary number system is perfect for representing numbers in digital systems (since only two digits, 0 and 1, are needed),

• A single bit can be stored in a two-state storage device often called a latch ,

• Binary numbers of length n can be stored in an n-bit long device known as a register.

Page 10: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.10/46Binary Numbers (Cont’d) …

• The digits: {0, 1}

• Examples: 11001112, 10101011112, 02, 112,

• 1101101101100112 (28,08310)

• MSB – Most Significant Bit,

• LSB – Least Significant Bit ,

MSB LSB

Page 11: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.11/46Binary Numbers (Cont’d) …

• Binary to Decimal ConversionMethod: Summation: Σ,

• Convert 100112 (Binary) to Base 10,

• …

• (Decimal):1*20 + 1*21 + 0*22 + 0*23 + 1*24

• (Decimal): 1*1 + 1*2 + 0*4 + 1*8 + 1*16 = 1910.

Page 12: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.12/46Binary Numbers (Cont’d) …

• Another Example:

• Convert 101110110012 (Binary) to Base 10,

• …

• (Decimal):1*20 + 0*21 + 0*22 +1*23 + 1*24 + 0*25 + 1*26 + 1*27 + 1*28 + 0*29 + 1*210 =

• (Decimal): 1*1 + 0*2 + 0*4 + 1*8 + 1*16 + 0*32 + 1*64 + 1*128 + 1*256 + 0*512 + 1*1024 = 149710.

Page 13: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.13/46Binary Numbers (Cont’d) …

• Decimal to Binary ConversionMethod: Use the successive division of two, keeping the residue as a binary digit and the result as the next number to divide.

• Let us take for example the decimal number of 4310.

• 43/2 = 21 and its residue is 1 (LSB) ,

• 21/2 = 10 and its residue is 1,

• 10/2 = 5 and its residue is 0,

• 5/2 = 2 and its residue is 1,

• 2/2 = 1 and its residue is 0,

• 1/2 = 0 and its residue is 1 (MSB)  ,

• The binary result is 1010112 .

Page 14: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.14/46Binary Numbers (Cont’d) …

• Decimal to Binary ConversionMethod: Division

• Convert 10810 (Decimal) to Base 2 (Binary):

• …

• 108/2 = 54 and remainder 0 (LSB) ,

• 54/2 = 27 and remainder 0,

• 27/2 = 13 and remainder 1,

• 13/2 = 6 and remainder 1,

• 6/2 = 3 and remainder 0,

• 3/2 = 1 and remainder 1,

• 1/2 = 0 and remainder 1 (MSB)  ,

• Result: 11011002 .

Page 15: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.15/46

• Numeric systems – general,

• Binary numbers,

• Octal numbers,

• Hexadecimal system,

• Data units,

• ASCII code,

• Negative number’s representation.

Page 16: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.16/46Octal Numbers …

• The digits: {0, 1, 2, 3, 4, 5, 6, 7} ,

• Examples: 12548, 257748, 33071228 ,

• Octal to Decimal Conversion Method: Summation Σ,

• Convert 12348 (Octal) to Base 10 (Decimal):

• …

• 4*80 + 3*81 + 2*82 + 1*83 + =

• 4*1 + 3*8 + 2*64 + 1*512 = 66810 .

Page 17: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.17/46Octal Numbers … (Cont’d)

• Decimal to Octal ConversionMethod: Division ,

• Convert 10810 (Decimal) to Base 8 (Octal):

• …

• 108/8 = 13 and remainder 4 (LSB),

• 13/8 = 1 and remainder 5,

• 1/8 = 0 and remainder 1 (MSB) ,

• Result: 1548 .

Page 18: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.18/46Octal Numbers … (Cont’d)

• Octal to Binary ConversionMethod: Substitution,

• Substitute any octal digit with three binary digits.

• 08 = 0002 18 = 0012 28 = 0102 38 = 0112

48 = 1002 58 = 1012 68 = 1102 78 = 1112,

• Convert 12348 (Octal) to Base 2 (Binary):

• …

• 001 010 011 1002 ,

• 1010 0111002 .

Page 19: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.19/46Octal Numbers (Cont’d)

• Binary to Octal ConversionMethod: Substitution,

• Convert 101110110012 (Binary) to Base 8 (Octal):

• …

• 10 111 011 0012 ,

• 010 111 011 0012 ,

• Result: 27318 .

Page 20: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.20/46

• Numeric systems – general,

• Binary numbers,

• Octal numbers,

• Hexadecimal system,

• Data units,

• ASCII code,

• Negative number’s representation.

Page 21: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.21/46Hexadecimal Numbers …

• The digits: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F} ,

• On the hexadecimal base we have 16 digits which go from 0 to 9 and from the letter A to the F, these letters represent the numbers from 10 to 15. Thus we count 016, 116, 216, 316, 416, 516, 616, 716, 816, 916, A16, B16, C16, D16, E16, F16 and 1016 ,

• Examples: 890A16, CC02FFE16, 12B16, B1216, 016, 1216, A216, 3FF0E7071A916 .

Page 22: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.22/46Hexadecimal Numbers (Cont’d) …

Dec Binary Oct Hex

0 0 0000 00 0

1 0 0001 01 1

2 0 0010 02 2

3 0 0011 03 3

4 0 0100 04 4

5 0 0101 05 5

6 0 0110 06 6

7 0 0111 07 7

Dec Binary Oct Hex

8 0 1000 10 8

9 0 1001 11 9

10 0 1010 12 A

11 0 1011 13 B

12 0 1100 14 C

13 0 1101 15 D

14 0 1110 16 E

15 0 1111 17 F

16 1 0000 20 10

Page 23: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.23/46Hexadecimal Numbers (Cont’d) …

• Hexadecimal to Decimal ConversionMethod: Summation Σ,

• Convert C0DE16 (HEX) to Base 10

• …

• (Decimal) 14*160 + 13*161 + 0*162 + 12*163 =

• (Decimal): 14*1 + 13*16 + 0*256 + 12*4096 = 4937410 .

Page 24: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.24/46Hexadecimal Numbers (Cont’d) …

• Decimal to Hexadecimal ConversionMethod: Division ,

• Convert 10810 (Decimal) to Base 16 (HEX):

• …

• 108/16 = 6 and remainder 12 (which is C16 ) (LSB) 

• 6/16 = 0 and remainder 6 (MSB) 

• Result: 6C16 .

Page 25: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.25/46Hexadecimal Numbers (Cont’d) …

• Hexadecimal to Binary ConversionMethod: Substitution ,

• Convert FFCE75516 (Hex) to Binary16,

• …

• 7FCEE5516 = 0111 1111 1100 1110 1110 0101 01012

=

• 1111111110011101110010101012 .

Page 26: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.26/46Hexadecimal Numbers … (Cont’d)

• Binary to Hexadecimal ConversionMethod: Substitution ,

• Convert 101110110012 (Binary) to Base 16 ,

• …

• 101110110012 =

• 101 1101 1001

• 0101 1101 10012 = 5D916 .

Page 27: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.27/46Hexadecimal Numbers (Cont’d) …

• Hexadecimal to Octal ConversionMethod: Substitution (via binary) ,

• Convert C0DE16 (HEX) to Base 8,

• …

• C0DE16 = 1100 0000 1101 11102

• 1100 0000 1101 11102 = 001 100 000 011 011 1102

• 001 100 000 011 011 1102 = 1403368 ,

Added leading 0s

Page 28: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.28/46Conversion Methods Diagram

10

168

2

Division / 16

Substitution

0

*n

nn BD

Division / 8

0

*n

nn BD

Substitutio

n

Divisio

n / 2

0

*n

nn BD

Page 29: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.29/46

• Numeric systems – general,

• Binary numbers,

• Octal numbers,

• Hexadecimal system,

• Data units,

• ASCII code,

• Negative number’s representation.

Page 30: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.30/46Data Units …

• In the computer memory we locate our data.

• The data may be:

• Bit wide (that is 1 or 0), 02 in a bit we can hold either 02 or 12,

• Nibble - 4 bits wide, 00002

in a nibble we can hold numbers from 02 to 11112

that is from 0 to 1510 ,

• Byte is 8 bits wide, 0000 00002

0 – 111111112, that is 0 to 25510 .

Page 31: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.31/46Data Units (Cont’d)

• Word is 16 bits wide , 0000 0000 0000 00002

0 – 1111 1111 1111 11112

that is 0 – 65,53510 ,

• Double Word is 32 bits wide0000 0000 0000 0000 0000 0000 0000 00002

0 – 1111 1111 1111 1111 1111 1111 1111 11112

that is 0 – 4,294,967,29510 ,

• Notice: all these are positive numbers, we haven’t touch yet any negative number.

Page 32: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.32/46

• Numeric systems – general,

• Binary numbers,

• Octal numbers,

• Hexadecimal system,

• Data units,

• ASCII code,

• Negative number’s representation.

Page 33: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.33/46ASCII Code …

• ASCII is an acronym of American Standard Code for Information Interchange,

• This code assigns the letters of the alphabet, decimal digits from 0 to 9 and some additional symbols a binary number of 7 bits, putting the 8th bit in its off state or 0 ,

• For example: Space has the ASCII code of 3016, that is 0011 00002,‘A’ has the ASCII code of 4116, that is 0110 00012,‘0’ has the ASCII code of 3016, that is 0011 00002.

Page 34: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.34/46ASCII Code (Cont’d) …

• This way each letter, digit or special character occupies one byte in the computer memory ,

• ASCII is very inefficient on the numeric aspect, since in binary format one byte is enough to represent numbers from 0 to 255, but on the other hand with the ASCII code one byte may represent only one digit. Due to this inefficiency, the ASCII code is mainly used in the memory to represent text.

Page 35: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.35/46ASCII Code (Cont’d) …

Page 36: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.36/46ASCII Code (Cont’d) …

Page 37: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.37/46ASCII Code (Cont’d)

• Translate the following:48656C6C6F20576F726C642116 ,

• …

• Hello World!

Page 38: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.38/46

• Numeric systems – general,

• Binary numbers,

• Octal numbers,

• Hexadecimal system,

• Data units,

• ASCII code,

• Negative number’s representation.

Page 39: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.39/46Negative number’s representation …

• So far we have seen only positive (and 0) numbers,

• How can we represent negative numbers in computers?

Page 40: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.40/46Neg. Num: 2’s complement

• The 2’complemet method:

• In this method the first bit is the sign…, but serves as part of the number as well.

Page 41: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.41/46The 2’complement Notation (Cont’d) …

• In order to achieve the 2’complemet representation of a number, do the following:

• A. Invert all the digits, that is 0 ->1 , and 1-> 0.Example: 010011102 ->101100012 (1’complemet) ,

• B. Add 1 to the result.Example 101100012 + 12 = 101100102 ,

• That is 101100102 is the 2’complemet of 010011102.

Page 42: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.42/46The 2’complement Notation (Cont’d) …

• Compute 001011012 – 000011002 (4510 – 1210),

• We will do this by adding 000011002 2’complement!

• Lets change 000011002 to its 2’complement,

• A. 00001100 -> 111100112 (1’complemet) ,

• B. 111100112 + 1 = 111101002 (2’complemet) ,

• Now let us sum these two numbers: 001011012 + 111101002 1:001000012 , that is 3310

Carry

Page 43: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.43/46The 2’complement Notation (Cont’d) …

• What is the 2’complemet of a 2’complemet?

• Example:

• 001101012 (5310)

• First 2’complemet:

• A. 001101012 -> 110010102 (1’complemet) ,

• B. 110010102 + 1 = 110010112 (2’complemet),

• Second 2’complement:

• A. 110010112 -> 001101002 (1’complemet),

• 001101002 + 1 = 001101012 (2’complemet) ,

Page 44: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.44/46The 2’complement Notation (Cont’d)

• With n bits you can represent the numbersfrom –2n-1 to +2n-1-1,

• -1 is a string of 1s,

• Zero is a string of 0s, (what is his 2’complemet?),

• –2n is 1 and the rest 0s ,

• +2n is invalid, unless you move to a larger register (i.e. a representation of a larger size).

Page 45: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.45/46Summary

• Numeric systems – general,

• Binary numbers,

• Octal numbers,

• Hexadecimal system,

• Data units,

• ASCII code,

• Negative number’s representation.

Page 46: EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,

EX_01.46/46

Numeric Systems

The End.