1 / 21

ICS312 Set 2

ICS312 Set 2. Representation of Numbers and Characters. 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

tamal
Download Presentation

ICS312 Set 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 * 103 + 3 * 102 + 2 * 101 + 5 * 100 For the decimal system: 10 = base 10 digits are: 0, 1, 2, 3, 4, 5, 6, 7, 8 , 9 The concept of positional representationapplies to the binary and hexadecimal numbering systems as well.

  3. Number Systems - Binary Number System Base = 22 Digits: 0, 1 Examples: 1001b = 1 * 23 + 0 * 22 + 0 * 21 + 1 * 20 = 8 + 1 = 9  1010 1101b = 1 * 27 + 1 * 25 + 1 * 23 + 1 * 22 + 1 = 128 + 32 + 8 + 4 + 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 = 1616 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E,F Examples: 10h = 1 * 161 + 0 * 160 = 16 (decimal)   200h = 2 * 16^2 = 2 * 256 = 512  45h = 4 * 16^ 1 + 5 = 69 3Fh = 3 * 16 + 15 = 48 + 15 = 63

  5. Converting from binary or hex to decimal: Use positional representation to expand the number and convert to decimal equivalent. Examples: 0011 1010b 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: ConvertDivision StepQuotient/RemainderBinary Digits 14 104

  7. Converting from hex to binary Rewrite each hex digit as its (4-digit) binary equivalent. Examples: Hex ValueBinary 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: BinaryHex Equivalent 1101 1011 0100 0111 b 0110 1111 1010 1001 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 1 + 1 b= 10b 1 + 1 + 1 b= 10b + 1= 11b Examples: 0011b0010 1101b +1001b + 0101 1110b =

  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 = 27 => range = -128 to 127 2 bytes = 16-1 bits = 215 => 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 9 - 5 using 2's complement formfor –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., 1011 1010 = 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 20 byte 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: 22 3F 4A 32 byte # in memory: 50 51 52 53 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 216 possible characters, it is possible to include characters of languages other that English, such as Chinese,Korean, Russian, etc.

More Related