Download
introduction to computer systems and software n.
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction to Computer Systems and Software PowerPoint Presentation
Download Presentation
Introduction to Computer Systems and Software

Introduction to Computer Systems and Software

106 Views Download Presentation
Download Presentation

Introduction to Computer Systems and Software

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Introduction to Computer Systems and Software Lecture 2 of 2 Simon Coupland simonc@dmu.ac.uk

  2. Representation of Data Within the Computer • Contents: • Decimal and Binary Integer Numbers • Binary Addition • Signed Binary Numbers • Overflow • Hexadecimal Numbers • Number Conversion • Real Numbers • Character Encoding

  3. Introduction • A few terms: • A bit – a single Binary digIT, 0 or 1 • A byte – eight bits • A word – one or more bytes • Integer – whole number • Real number – a number with decimal points • Binary – Base 2 numbers • Octal – Base 8 numbers • Decimal – Base 10 numbers (everyday numbers) • Hexadecimal – Base 16 numbers

  4. Decimal and Binary Numbers • We all use decimal numbers • Base 10 numbers • Example: 124

  5. Decimal and Binary Numbers • Computers use binary numbers • Base 2 numbers: • Example: 124

  6. Decimal and Binary Numbers • More binary numbers: 00010011 = 16 + 2 + 1 = 19 01011101 = 64 + 16 + 8 + 4 + 1 = 93 11111111 = 255 00000000 = 0

  7. Binary Addition • When adding binary numbers we use binary logic • Binary Addition Truth Table 1:

  8. Binary Addition • Binary Addition Truth Table 2:

  9. Binary Addition • Binary Addition Example: 00010001 + 00011101 =

  10. Binary Addition • Binary Addition Example: 00010001 + 00011101 = 0 1

  11. Binary Addition • Binary Addition Example: 00010001 + 00011101 = 10

  12. Binary Addition • Binary Addition Example: 00010001 + 00011101 = 110

  13. Binary Addition • Binary Addition Example: 00010001 + 00011101 = 1110

  14. Binary Addition • Binary Addition Example: 00010001 + 00011101 = 01110 1

  15. Binary Addition • Binary Addition Example: 00010001 + 00011101 = 101110

  16. Binary Addition • Binary Addition Example: 00010001 + 00011101 = 0101110

  17. Binary Addition • Binary Addition Example: 00010001 + 00011101 = 00101110

  18. Binary Addition • Binary Addition Q1: 00101101 + 00011001 =

  19. Binary Addition • Binary Addition Q1: 00101101 + 00011001 = 01000110

  20. Binary Addition • Binary Addition Q2: 00001110 + 00001111 =

  21. Binary Addition • Binary Addition Q2: 00001110 + 00001111 = 00011101

  22. Binary Addition • Binary Addition Q3: 01011001 + 00111011 =

  23. Binary Addition • Binary Addition Q3: 01011001 + 00111011 = 10010011

  24. Negative Binary Numbers • Sign-true Magnitude • Left most bit holds sign • Example: -10

  25. Negative Binary Numbers • Ones complement • All 1’s and 0’s are switched • When negative, result = -255 + value • Example: -10

  26. Negative Binary Numbers • Twos complement • Left most bit holds sign • When negative, result = -128 + result • Example: -10

  27. Negative Binary Numbers • Conversion to Twos complement • Ones complement the byte/word • Add 1 • Example: 00001010 +10 11110101 Ones complement + 00000001 = 11110110

  28. Why Use Twos Complement? • Because addition rules still work: 00010110 22 + 10001000 + -120 = 10011110 = -98

  29. Overflow • Overflow is when the number of bits is too small to store the result of an arithmetic operation • Example (twos complement) : 01011001 89 + 01111011 + 123 = 11010011 = -45

  30. Overflow • Overflow can be easily detected for signed binary numbers • Errors can then be corrected • Adding two positive numbers should give a positive result • Adding two negative numbers should give a negative result • Adding a positive and negative number together can never result in overflow. Why?

  31. Hexadecimal Numbers • Writing code with long binary numbers would be cumbersome and error prone • A hexadecimal digit can take 16 values (0-F) • One hex digit can represent a four bit word • Examples:

  32. Number Conversion • Binary to Hexadecimal: • From the least significant (rightmost) bit split the binary number into groups of four bits. • Each 4 bits has a hexadecimal equivalent • Example: 0001001110011110 0001 0011 1001 1110 1 3 9 E 139E

  33. Number Conversion • Hexadecimal to Binary: • Convert each hexadecimal digit into its 4 bit binary equivalent • Join the all 4 bit words together • Example: A42F A 4 2 F 1010 0100 0010 1111 1010010000101111

  34. Number Conversion • Question • Hexadecimal to Binary: • Convert D36B into binary

  35. Number Conversion • Question • Hexadecimal to Binary: • Convert D36B into binary D 3 6 B 1101 0011 0110 1011

  36. Number Conversion • Question • Binary to Hexadecimal: • Convert 1001101001001010 into hexadecimal

  37. Number Conversion • Question • Binary to Hexadecimal: • Convert 1001101001001010 into hexadecimal 1001 1010 0100 1010 9 A 8 A 9A8A

  38. Number Conversion • Decimal to Binary • Use the following algorithm, begin with LSB int dec_value = some_number; int next_bit; while(dec_value > 0) { next_bit = dec_value % 2; dec_value = dec_value / 2; }

  39. Number Conversion • Decimal to Binary • Convert 42 to binary:

  40. Number Conversion • Question • Convert 39 to binary:

  41. Number Conversion • Question • Convert 39 to binary:

  42. Number Conversion • Binary to Decimal • Use the following algorithm, begin with MSB int dec_value = 0; int bit_value; int bit_index = MSB_index; while(bit_index >= 0) { bit_value = word[bit_index]; dec_value = dec_value * 2 + bit_value; bit_index--; }

  43. Number Conversion • Binary to Decimal • Convert 011010 to decimal:

  44. Number Conversion • Binary to Decimal • Question, convert 101110 to decimal:

  45. Number Conversion • Binary to Decimal • Question, convert 101110 to decimal:

  46. Number Conversion • Decimal to Hexadecimal • Use the following algorithm, begin with LSB int dec_value = some_number; char hex_digit; while(dec_value > 0) { hex_digit = to_hex(dec_value % 16); dec_value = dec_value / 16; }

  47. Number Conversion • Decimal to Hexadecimal • Convert 1863 to hexadecimal

  48. Number Conversion • Decimal to Hexadecimal • Question, convert 1437 to hexadecimal

  49. Number Conversion • Decimal to Hexadecimal • Question, convert 1437 to hexadecimal

  50. Number Conversion • Hexadecimal to Decimal • Use the following algorithm, begin with MSB int dec_value = 0; char digit_value; while(!word.off) { digit_value = to_dec(hex_digit); dec_value = dec_value * 16 + digit_value; }