Presentation is loading. Please wait.

Presentation is loading. Please wait.

3.1 Denary, Binary and Hexadecimal Number Systems

Similar presentations


Presentation on theme: "3.1 Denary, Binary and Hexadecimal Number Systems"— Presentation transcript:

1 3.1 Denary, Binary and Hexadecimal Number Systems
We use the denary (base 10) number system in our daily life for counting and calculation. Computers use the binary (base 2) number system for data representations and manipulations. Programmers use hexadecimal (base 16) number system to communicate with computers.

2 3.1 Denary, Binary and Hexadecimal Number Systems
Denary (base 10) Binary (base 2) Hexadecimal (base 16) 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 Different representations of number values from 0 to 9 using denary, binary and hexadecimal number systems

3 3.1 Denary, Binary and Hexadecimal Number Systems
Denary (base 10) Binary (base 2) Hexadecimal (base 16) 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F Different representations of number values from 10 to 15 using denary, binary and hexadecimal number systems

4 3.1 Denary, Binary and Hexadecimal Number Systems
Denary (base 10) Binary (base 2) Hexadecimal (base 16) 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F Different representations of number values from 10 to 15 using denary, binary and hexadecimal number systems

5 3.2 Number System Conversion
From a Binary Number or a Hexadecimal Number to a Denary Number By evaluating the place values of the digits of a binary number or hexadecimal number, we can find the corresponding values in the denary number system. Binary to Denary Hexadecimal to Denary

6 3.2 Number System Conversion
From a Binary Number or a Hexadecimal Number to a Denary Number Binary to Denary Only digits 0 and 1 are used in the binary number system. The binary number in its expanded form is: Therefore, = 1 × × × × 20  = 1110 Binary digit 1 Place value 23 22 21 20 Digit value 1 × 23 0 × 22 1 × 21 1 × 20

7 3.2 Number System Conversion
From a Binary Number or a Hexadecimal Number to a Denary Number Hexadecimal to Denary In the hexadecimal number system, the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F are used. A, B, C, D, E, F represent 10, 11, 12, 13, 14, 15 respectively. The hexadecimal number 2CA916 in its expanded form is: Therefore, 2CA916 = 2 × C × A × × 160  = Hexadecimal digit 2 C A 9 Place value 163 162 161 160 Digit value 2 × 163 C × 162 A × 161 1 × 160

8 3.2 Number System Conversion
From a Denary Number to a Binary Number or a Hexadecimal Number To convert a denary number to another number system with base b: 1. Divide the denary number by b repetitively until the quotient   is smaller than b. 2. Obtain the answer by writing up from the quotient to the   remainders in reverse order.

9 3.2 Number System Conversion
From a Binary Number to a Hexadecimal Number To convert a binary number into a hexadecimal number: 1. Group the digits of the binary number by four starting from   the righthand side. 2. Replace each group of the four digits by an equivalent   hexadecimal digit.

10 3.2 Number System Conversion
From a Hexadecimal Number to a Binary Number To convert a hexadecimal number into a binary number: 1. Convert each digit of the hexadecimal number into a group   of four binary digits. 2. Obtain the binary number by grouping all the binary digits   together. The big problem with the binary system is verbosity. For example: A decimal value 202 requires 8 binary digits, making it difficult to read and remember. Hexadecimal numbers are much more compact than binary numbers and it is easy to convert from a hexadecimal number to a binary number and vice versa.

11 3.2 Number System Conversion
From a Hexadecimal Number to a Binary Number To convert a hexadecimal number into a binary number: 1. Convert each digit of the hexadecimal number into a group   of four binary digits. 2. Obtain the binary number by grouping all the binary digits   together. The big problem with the binary system is verbosity. For example: A decimal value 202 requires 8 binary digits, making it difficult to read and remember. Hexadecimal numbers are much more compact than binary numbers and it is easy to convert from a hexadecimal number to a binary number and vice versa.

12 3.3 Number Representation in Computer Systems
Binary number system the only number system that a computer uses in storing numbers and performing arithmetic Bit, Byte and Word Bit A single binary digit The basic unit for storing data in a computer A single bit can only represent two distinct values. For example: 0 or 1, True or False, On or Off If more distinct values need to be represented, a series of bits can be used. For example: A 8-bit binary number can hold 256 distinct values. An n-bit binary number can represent 2n distinct values.

13 3.3 Number Representation in Computer Systems
Bit, Byte and Word Byte A data unit used in computers Consists of 8 bits and is the smallest addressable unit in a microprocessor. Unit Abbreviation Remark Bit b The basic unit of a binary digit Byte B 1 B = 8 b Kilobyte KB 1 KB = 210 B = 1,024 bytes Megabyte MB 1 MB = 220 B = 1,024 KB (or 1,048,576 bytes) Gigabyte GB 1 GB = 230 B = 1,024 MB (about 1 billion bytes) Terabyte TB 1 TB = 240 B = 1,024 GB (about 1 trillion bytes) Measurement units of data

14 3.3 Number Representation in Computer Systems
Bit, Byte and Word Word Modern computers can handle data stored in two or more bytes at a time. The natural unit of data used by a computer is called a word. The word length (word size) is measured in bits. Modern computers usually have a word length of 16, 32 or 64 bits.

15 3.3 Number Representation in Computer Systems
Representation of Unsigned Binary Integer Unsigned integer is a type of integer representation that contains no sign symbol. Non-negative integers such as population and sales volume of books can be represented by unsigned integers. All bits in a word are used to represent the magnitude.

16 Minimum unsigned binary Maximum unsigned binary
3.3 Number Representation in Computer    Systems Representation of Unsigned Binary Integer Word length Minimum unsigned binary integer allowed Maximum unsigned binary 4-bit 00002 = 010 11112 = 1510 8-bit = 25510 16-bit = 65,53510 24-bit = 16,777,21510 Minimum and maximum unsigned values of various word lengths

17 3.3 Number Representation in Computer Systems
Representation of Signed Binary Integer Two common methods to represent signed binary integers: Sign-and-magnitude Two’s complement

18 3.3 Number Representation in Computer Systems
Representation of Signed Binary Integer Sign-and-magnitude The leftmost bit, known as sign bit, is used to specify the sign of a binary integer. The sign bit: 0: a positive integer 1: a negative integer The rest of the bits are used to store the magnitude of the binary number.

19 Minimum signed binary integer Maximum signed binary integer
3.3 Number Representation in Computer    Systems Representation of Signed Binary Integer Sign-and-magnitude Word length Minimum signed binary integer allowed Maximum signed binary integer 4-bit 11112 = –710 01112 = 710 8-bit = –12710 = 12710 16-bit = –32,76710 = 32,76710 24-bit = –8,388,60710 = 8,388,60710 Minimum and maximum values represented by sign-and-magnitude integers in different word lengths

20 3.3 Number Representation in Computer Systems
Representation of Signed Binary Integer Sign-and-magnitude The shortfall is that there are two representations of zero: Both and represent zero in an 8-bit signed binary integer. It is rarely used in computer systems.

21 3.3 Number Representation in Computer Systems
Representation of Signed Binary Integer Two’s Complement Widely used in computers to represent binary integers All integers have unique representations. Two’s complement 0111 0110 0101 0100 0011 0010 0001 0000 Decimal value 7 6 5 4 3 2 1 Two’s complement 1111 1110 1101 1100 1011 1010 1001 1000 Decimal value -1 -2 -3 -4 -5 -6 -7 -8 Two’s complement of a 4-bit integer

22 3.3 Number Representation in Computer Systems
Representation of Signed Binary Integer Two’s Complement Representation of a positive binary integer is exactly the same as that of the original value To get a negative binary integer: Starting from the corresponding positive binary integer, invert all bits from ‘0’ to ‘1’ and ‘1’ to ‘0’ . The result is known as one’s complement. Add 1 to the one’s complement. The above steps can also be used to convert a negative binary integer into a positive binary integer.

23 3.3 Number Representation in Computer Systems
Representation of Signed Binary Integer Two’s Complement Word length Smallest negative binary integer allowed Largest positive binary integer allowed Two’s complement Denary value 4-bit 10002 –810 01112 710 8-bit –12810 12710 16-bit –32,76810 32,76710 Minimum and maximum two’s complement values and their corresponding denary values of various word lengths

24 3.3 Number Representation in Computer Systems
Representation of Signed Binary Integer Two’s Complement Word length Smallest negative binary integer allowed Largest positive binary integer allowed Two’s complement Denary value 4-bit 10002 –810 01112 710 8-bit –12810 12710 16-bit –32,76810 32,76710 Minimum and maximum two’s complement values and their corresponding denary values of various word lengths

25 3.4 Addition and Subtraction of Different Number Representations
Addition and Subtraction of Unsigned Integers The calculation on both addition and subtraction of unsigned integers in other number systems is the same as that in the denary system. A ‘carry’ is generated when the sum of digits equals or exceeds the base value. A ‘borrow’ from the left digit is necessary if a larger digit is subtracted from a smaller one.

26 3.4 Addition and Subtraction of Different Number Representations
Addition and Subtraction of Unsigned Integers Overflow Error Occur when the calculation result is outside the range that the digits can represent. For example:   – _     1    +_ Carry digit cannot be stored in the resulting bit pattern. Borrow occurs to the left of the leftmost bit. Examples of overflow errors

27 3.4 Addition and Subtraction of Different Number Representations
Addition and Subtraction of Two’s Complement Numbers No matter what the sign bits are, the addition of two’s complement numbers are exactly the same as the addition of two unsigned binary integers. Overflow error occurs when two numbers of the same sign are added and the result has the opposite sign.

28 3.4 Addition and Subtraction of Different Number Representations
Addition and Subtraction of Two’s Complement Numbers No matter what the sign bits are, the addition of two’s complement numbers are exactly the same as the addition of two unsigned binary integers. Overflow error occurs when two numbers of the same sign are added and the result has the opposite sign.

29 3.5 Character Coding Systems
Other than numeric data, a computer needs to store and process characters. The character coding system is a way to represent characters in a form that can be manipulated efficiently in a computer.

30 3.5 Character Coding Systems
ASCII Two common character coding systems: American Standard Code for Information Interchange (ASCII) Extended Binary-Coded Decimal Interchange Code (EBCDIC) Each code represents either a printable character or a non-printable character (e.g. end-of-line character) Each ASCII character consists of 7 bits, and it can contain 27 (i.e. 128) different characters. They include all the alphanumeric characters (the small and capital English letters, digits from 0 to 9) and graphics symbols.

31 3.5 Character Coding Systems
ASCII Dec Binary Character 032 SP 046 . 060 < 033 ! 047 / 061 = 034 " 048 062 > 035 # 049 1 063 ? 036 $ 050 2 064 @ 037 % 051 3 065 A 038 & 052 4 066 B 039 ' 053 5 067 C 040 ( 054 6 068 D 041 ) 055 7 069 E 042 * 056 8 070 F 043 + 057 9 071 G 044 , 058 : 072 H 045 - 059 ; 073 I ASCII code table

32 3.5 Character Coding Systems
ASCII Dec Binary Character 074 J 088 X 102 f 075 K 089 Y 103 g 076 L 090 Z 104 h 077 M 091 [ 105 i 078 N 092 \ 106 j 079 O 093 ] 107 k 080 P 094 ^ 108 l 081 Q 095 _ 109 m 082 R 096 ` 110 n 083 S 097 a 111 o 084 T 098 b 112 p 085 U 099 c 113 q 086 V 100 d 114 r 087 W 101 e 115 s ASCII code table

33 3.5 Character Coding Systems
ASCII In practice, the 7-bit ASCII code is often embedded in an 8-bit code, where the leftmost bit is set as ‘0’. Dec Binary Character 116 t 120 x 124 | 117 u 121 y 125 } 118 v 122 z 126 ~ 119 w 123 { 127 DEL ASCII code table

34 3.5 Character Coding Systems
Chinese Character Coding Systems The standard ASCII: 128 characters The extended ASCII: 256 characters There are more than 100,000 Chinese characters and we use more than 10,000 of them in our daily lives. Chinese characters are usually represented in: Big5 code Guo Biao (GB) code Unicode

35 3.5 Character Coding Systems
Chinese Character Coding Systems Big5 code: traditional Chinese GB code: simplified Chinese Both character coding systems use two bytes to represent one Chinese character. If a Chinese text file is processed with the wrong coding system, strange and meaningless characters will appear.

36 3.5 Character Coding Systems
Chinese Character Coding Systems Hexadecimal representation Binary representation Character represented in Big5 code Character represented in GB code AA40 AA41 AA42 AA43 Examples of Chinese characters represented in Big5 code and GB codes

37 3.5 Character Coding Systems
Unicode Used to represent all the existing languages in the world Contain about 100,000 characters The representations of Unicode known as code points are variable in length. Made up of one to four bytes The code points are carefully defined so that the most frequently used characters, such as the ASCII codes, are put at the front of the code table. These characters can be represented by a one-byte code point.

38 Hexadecimal representation Binary representation
3.5 Character Coding Systems Unicode Hexadecimal representation Binary representation Character 4E3D 4E3E 4EAD 4EAE Examples of Unicode

39 Hexadecimal representation Binary representation
3.5 Character Coding Systems Unicode Hexadecimal representation Binary representation Character 4E3D 4E3E 4EAD 4EAE Examples of Unicode


Download ppt "3.1 Denary, Binary and Hexadecimal Number Systems"

Similar presentations


Ads by Google