Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— 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) 000000 100011 200102 300113 401004 501015 601106 701117 810008 910019 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) 101010A 111011B 121100C 131101D 141110E 151111F 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) 101010A 111011B 121100C 131101D 141110E 151111F 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 1011 2 in its expanded form is: Therefore, 1011 2 = 1 × 2 3 + 0 × 2 2 + 1 × 2 1 + 1 × 2 0 = 11 10 Binary digit1011 Place value23232 2121 2020 Digit value1 × 2 3 0 × 2 2 1 × 2 1 1 × 2 0

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 2CA9 16 in its expanded form is: Therefore, 2CA9 16 = 2 × 16 3 + C × 16 2 + A × 16 1 + 9 × 16 0 = 11433 10 Hexadecimal digit2CA9 Place value16 3 16 2 16 1 16 0 Digit value2 × 16 3 C × 16 2 A × 16 1 1 × 16 0

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 2 n 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. UnitAbbreviationRemark BitbThe basic unit of a binary digit ByteB1 B = 8 b KilobyteKB1 KB = 2 10 B = 1,024 bytes MegabyteMB1 MB = 2 20 B = 1,024 KB (or 1,048,576 bytes) GigabyteGB1 GB = 2 30 B = 1,024 MB (about 1 billion bytes) TerabyteTB1 TB = 2 40 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 3.3 Number Representation in Computer Systems Representation of Unsigned Binary Integer Word length Minimum unsigned binary integer allowed Maximum unsigned binary integer allowed 4-bit 0000 2 = 0 10 1111 2 = 15 10 8-bit 0000 0000 2 = 0 10 1111 1111 2 = 255 10 16-bit 0000 0000 0000 0000 2 = 0 10 1111 1111 1111 1111 2 = 65,535 10 24-bit 0000 0000 0000 0000 0000 0000 2 = 0 10 1111 1111 1111 1111 1111 1111 2 = 16,777,215 10 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 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 allowed 4-bit 1111 2 = –7 10 0111 2 = 7 10 8-bit 1111 1111 2 = –127 10 0111 1111 2 = 127 10 16-bit 1111 1111 1111 1111 2 = –32,767 10 0111 1111 1111 1111 2 = 32,767 10 24-bit 1111 1111 1111 1111 1111 1111 2 = –8,388,607 10 0111 1111 1111 1111 1111 1111 2 = 8,388,607 10 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 1000 0000 2 and 0000 0000 2 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 01110110010101000011001000010000 Decimal value 76543210 Two’s complement 11111110110111001011101010011000 Decimal value -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 complementDenary valueTwo’s complementDenary value 4-bit1000 2 –8 10 0111 2 7 10 8-bit1000 0000 2 –128 10 0111 1111 2 127 10 16-bit1000 0000 0000 0000 2 –32,768 10 0111 1111 1111 1111 2 32,767 10 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 complementDenary valueTwo’s complementDenary value 4-bit1000 2 –8 10 0111 2 7 10 8-bit1000 0000 2 –128 10 0111 1111 2 127 10 16-bit1000 0000 0000 0000 2 –32,768 10 0111 1111 1111 1111 2 32,767 10 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: 1111 0000 + _ 0001 1100 1 0000 1100 Examples of overflow errors 0000 1000 – _ 0001 1000 1111 0000 1 Carry digit cannot be stored in the resulting bit pattern. Borrow occurs to the left of the leftmost bit.

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 2 7 (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 DecBinaryCharacterDecBinaryCharacterDecBinaryCharacter 0320100000SP0460101110.0600111100< 0330100001!0470101111/0610111101= 0340100010"048011000000620111110> 0350100011#049011000110630111111? 0360100100$050011001020641000000@ 0370100101%051011001130651000001A 0380100110&052011010040661000010B 0390100111'053011010150671000011C 0400101000(054011011060681000100D 0410101001)055011011170691000101E 0420101010*056011100080701000110F 0430101011+057011100190711000111G 0440101100,0580111010:0721001000H 0450101101-0590111011;0731001001I ASCII code table

32 3.5 Character Coding Systems ASCII DecBinaryCharacterDecBinaryCharacterDecBinaryCharacter 0741001010J0881011000X1021100110f 0751001011K0891011001Y1031100111g 0761001100L0901011010Z1041101000h 0771001101M0911011011[1051101001i 0781001110N0921011100\1061101010j 0791001111O0931011101]1071101011k 0801010000P0941011110^1081101100l 0811010001Q0951011111_1091101101m 0821010010R0961100000`1101101110n 0831010011S0971100001a1111101111o 0841010100T0981100010b1121110000p 0851010101U0991100011c1131110001q 0861010110V1001100100d1141110010r 0871010111W1011100101e1151110011s 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’. DecBinaryCharacterDecBinaryCharacterDecBinaryCharacter 1161110100t1201111000x1241111100| 1171110101u1211111001y1251111101} 1181110110v1221111010z1261111110~ 1191110111w1231111011{1271111111DEL 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 AA401010 1010 0100 0000 昇狜 AA411010 1010 0100 0001 服狝 AA421010 1010 0100 0010 朋狟 AA431010 1010 0100 0011 杭狢 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 3.5 Character Coding Systems Unicode Hexadecimal representationBinary representationCharacter 4E3D0100 1110 0011 1101 麗 4E3E0100 1110 0011 1110 舉 4EAD0100 1110 1010 1101 亭 4EAE0100 1110 1010 1110 亮 Examples of Unicode

39 3.5 Character Coding Systems Unicode Hexadecimal representationBinary representationCharacter 4E3D0100 1110 0011 1101 麗 4E3E0100 1110 0011 1110 舉 4EAD0100 1110 1010 1101 亭 4EAE0100 1110 1010 1110 亮 Examples of Unicode


Download ppt "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."

Similar presentations


Ads by Google