Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.

Similar presentations


Presentation on theme: "Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers."— Presentation transcript:

1 Chapter 1 Representing Data in a Computer

2 1.1 Binary and Hexadecimal Numbers

3 Decimal Numbers Base 10 4053 = 3 x 1 + 5 x 10 + 0 x 10 2 + 4 x 10 3 1s 10s 100s 1000s

4 Binary Numbers Base 2, using bits (binary digits) 0 and 1 10111 = 1 x 1 + 1 x 2 + 1 x 2 2 + 0 x 2 3 + 1 x 2 4 1s 2s 4s 8s 16s 10111 2 = 23 10

5 Hexadecimal Numbers Base 16 Digits –0-9 same as decimal –A for 10 –B for 11 –C for 12 –D for 13 –E for 14 –F for 15

6 Hexadecimal to Decimal Base 16 5CB = 11 x 1 + 12 x 16 + 5 x 16 2 1s 16s 256s 5CB 16 = 1483 10

7 Using Windows Calculator

8 Converting decimal to hex Use a calculator that does hex calculations or Use this algorithm repeat divide DecimalNumber by 16, getting Quotient and Remainder; Remainder (in hex) is the next digit (right to left); DecimalNumber := Quotient; until DecimalNumber = 0;

9 1.2 Character Codes

10 Character Codes Letters, numerals, punctuation marks and other characters are represented in a computer by assigning a numeric value to each character The system commonly used with microcomputers is the American Standard Code for Information Interchange (ASCII)

11 Examples of ASCII Codes Printable characters –Uppercase M codes as 4D 16 = 1001101 2 –Lowercase m codes as 6D 16 = 1101101 2 –Numeral 5 codes as 35 16 –Space codes as 20 16 Control characters –Backspace codes as 08 16 Carriage return CR (0D 16 ) and linefeed LF (0A 16 ) together create a line break

12 1.3 Unsigned and Signed Integers

13 Standard Number Lengths Byte – 8 bits Word – 16 bits Doubleword – 32 bits Quadword – 64 bits

14 Unsigned Representation Just binary in one of the standard lengths E47A is the word-length unsigned representation for the decimal number 58490

15 Signed Representation 2’s complement representation used in 80x86 One of the standard lengths High-order (leading) bit gives sign –0 for positive –1 for negative For a negative number, you must perform the 2’s complement operation to find the corresponding positive number

16 2’s Complement Operation +/- button on many calculators Manually by subtracting from 100…0 E47A represents a negative word-length signed number since E = 1110 10000 – E47A = 1B86 = 7046 10, so E47A is the 2’s complement signed representation for -7046 minus

17 Multiple Interpretations One pattern of bits can have many different interpretations The word FE89 can be interpreted as –An unsigned number whose decimal value is 65513 –A signed number whose decimal value is -375

18 1.4 Integer Addition and Subtraction

19 Addition Same for unsigned and 2’s complement signed numbers, but the results may be interpreted differently The two numbers will be byte-size, word- size, doubleword-size or quadword-size Add the bits and store the sum in the same length as the operands, discarding an extra bit (if any)

20 Carry If the sum of two numbers is one bit longer than the operand size, the extra 1 is a carry (or carry out). A carry is discarded when storing the result, but we’ll see how the 80x86 CPU records it. For unsigned numbers, a carry means that the result was too large to be stored – the answer is wrong.

21 Carry In A 1 carried into the high-order (sign, leftmost) bit position during addition is called a carry in. Byte-length example 11111 11100111E7 +11110110+F6 1110111011DD carry out carry in

22 Overflow Overflow occurs when there is a carry in but no carry out, or when there is a carry out but no carry in. It recorded by the CPU. If overflow occurs when adding two signed numbers, then the result will be incorrect. Word-length example –Overflow, so AC99 incorrect if viewed as sum of signed numbers –No carry, so AC99 correct if viewed as sum of unsigned numbers 483F + 645A AC99

23 Subtraction Take the 2’s complement of second number and add it to the first number Overflow occurs in subtraction if it occurs in the corresponding addition CF is set for a borrow in subtraction – when the second number is larger than the first as unsigned numbers. There is a borrow in subtraction when there is not a carry in the corresponding addition.

24 1.5 Other Systems For Representing Numbers

25 1’s complement Similar to 2’s complement but to negate a number you flip all its bits. The 1’s complement of 01110000 is 10001111 1’s complement rarely used for signed integers in modern systems

26 Binary Coded Decimal BCD uses four bits to encode each decimal digit 479 could be encoded in two bytes as 0000 0100 0111 1001 The Intel architecture has only a few instructions to do arithmetic on BCD numbers

27 Floating Point IEEE single precision is a popular 32-bit format –Write the number in base 2 “scientific notation” –Sign bit (0 positive, 1 negative) –8 bits for exponent (actual exponent plus a bias of 127) –23 bits for fraction (omitting the leading 1)

28 Floating Point Example 78.375 10 = 1001110.011 2 1001110.011 2 = 1.001110011  2 6 0 10000101 00111001100000000000000 sign + exponent,127+6 in binary fraction, with leading 1 removed and trailing 0’s added to make 23 bits


Download ppt "Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers."

Similar presentations


Ads by Google