Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICS312 Set 2 Representation of Numbers and Characters.

Similar presentations

Presentation on theme: "ICS312 Set 2 Representation of Numbers and Characters."— Presentation transcript:

1 ICS312 Set 2 Representation of Numbers and Characters

2 Number Systems - Decimal System (base 10) Uses positional representation Each digit in a number is associated with a power of 10 based on its position in the number. The one's digit (zero power of 10) is the rightmost digit and the powers of 10 increase as you move to the left. 5,325 = 5 * * * * 10 0 For the decimal system: 10 = base 10 digits are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 The concept of positional representation applies to the binary and hexadecimal numbering systems as well.

3 Number Systems - Binary Number System Base = 2 2 Digits: 0, 1 Examples: 1001b = 1 * * * * 2 0 = = b = 1 * * * * = = 173 Note: it is common to put binary digits in groups of 4 to make it easier to read them.

4 Number Systems - Hexadecimal Number System Used as a shorter, easier to read notation than binary. Base = digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E,F Examples: 10h = 1 * * 16 0 = 16 (decimal) 200h = 2 * 16^2 = 2 * 256 = h = 4 * 16^ = 69 3Fh = 3 * = = 63

5 Converting from binary or hex to decimal: Use positional representation to expand the number and convert to decimal equivalent. Examples: b 015Eh

6 Converting from decimal to binary: Use repeated division by 2. The remainders give the binary digits, starting from the lowest power of 2. Examples: Convert Division Step Quotient/Remainder Binary Digits

7 Converting from hex to binary Rewrite each hex digit as its (4-digit) binary equivalent. Examples: Hex Value Binary equivalent 4Bh 32FFh F38Bh

8 Converting from binary to hex Rewrite each group of 4 binary digits as its hex equivalent. Pad zeroes on the left as needed. Examples: Binary Hex Equivalent b b

9 Converting from decimal to hexadecimal: It’s simplest to convert the decimal number to binary and then convert that binary number to hexadecimal.

10 Arithmetic Apply the same concepts as for decimal arithmetic to binary and hexadecimal arithmetic.

11 Binary Addition: Underlying examples: how carries work b = 10b b = 10b + 1 = 11b Examples: 0011b b b b =

12 Hexadecimal Addition: Underlying examples: how carries work F + 1 h = 10h E + 2 h = 10h A + B h = 10d + 11d = 21d = 15h Examples: 4Ah + 5Bh = 4B7Fh + 2A93h =

13 Representing Integers in the Computer (1) Signed Numbers and Unsigned Numbers Most Significant Bit (MSB) leftmost or high-order bit (bit 15 or 7) Least Significant Bit (LSB) rightmost or low-order bit (bit 0)

14 Representing Integers in the Computer (2) Signed Integers Allows positive and negative integers to be represented MSB used to indicate sign: 0 = positive, 1 = negative Since 1 bit is used to represent the sign, only 7 or 15 bits can be used for the magnitude, with positive and negative values for each + one extra negative value: 1 byte = 8-1 bits = 2 7 => range = -128 to bytes = 16-1 bits = 2 15 => range = -32,768 to +32,767

15 Representing Integers in the Computer (3) 1's Complement Formed by reversing (complementing) each bit of value. 2's Complement form Formed by adding 1 to 1's complement of a number. Examples: Express -9 in 2's complement form (8-bit) Add 9 and its 2's complement value, ignoring carries: What is 2's complement of –5? Calculate using 2's complement form for –5, ignoring carries.

16 Intel's peculiar method of storing multibyte numbers in the computer Note: each hex digit is encoded in a nibble (4 bits). e.g., = BAh Example of a multibyte number: 3A 4D is a 2 byte hex number The memory of the computer is numbered byte 0, byte 1, byte 2,.. For this example, if the number is stored at bytes 20 and 21, it is stored as follows: byte 20byte 21 4D 3A

17 Intel's peculiar method of storing multibyte numbers in the computer (Cont. 1) The address of the 2 byte word (a word is 2 bytes, a byte is 8 bits) is given as the lowest address used, which is byte 20. Note again that the bytes are stored in reverse order with the least significant byte at the lowest memory address and the most significant byte stored at the highest memory address.

18 Intel's peculiar method of storing multibyte numbers in the computer (Cont. 2) Example with a double word (= 2 words or 4 bytes). E.g., 32 4A 3F 22h This would be stored in memory as: memory contents:223F4A32 byte # in memory: The address for the (entire) number stored in memory is 50, which is the lowest memory address used.

19 Character Representation ASCII American Standard Code for Information Interchange Standard encoding scheme used to represent characters in binary format on personal computers 7-bit encoding => 128 characters can be represented codes 0-31 and 127 are control characters (nonprinting characters) control characters used on PC's are: LF, CR, BS, Bell, HT, FF

20 Character Representation (Cont.) ASCII characters codes are used for input and output. E.g., when the number 5, is entered on the keyboard, the value read into the processor is the ASCII character code 35h. In order to do numeric processing, the ASCII code must be converted to the true numeric value by subtracting 30h, which gives the value 5. Then, before the result can be displayed the numeric value must be reconverted to an ASCII code which can be displayed

21 Character Representation (Cont.) UNIDEC is a system (supported e.g by HTML) for representing characters employing 2 bytes per character. With 2 16 possible characters, it is possible to include characters of languages other that English, such as Chinese,Korean, Russian, etc.

Download ppt "ICS312 Set 2 Representation of Numbers and Characters."

Similar presentations

Ads by Google