1 / 79

Data Representation in Computers

Learn about binary and decimal number systems, counting methods, hexadecimal numbers, conversions between systems, character representation, ASCII and EBCDIC codes, integer representation, two's complement, and more in computer data representation.

tmaynard
Download Presentation

Data Representation in Computers

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. Representation of Data Within the Computer • All data within is stored and processed as Binary • Base 2 Number system only TWO characters are allowed 0 or 1 • Binary digits = “Bits” • Two state system is ideal for a variety of storage/processing methods e.g. • CDROMs Lands or pits • Barcodes black or white lines • Paper tape holes or no holes • Cards pencil mark or no pencil mark

  2. Denary (Decimal) Number System • Placement of each digit determines its value • In Decimal, powers of 10 provide the value of each column

  3. Binary Number System • In Binary, being a base 2 number system, powers of 2 provide the value of each column.

  4. Counting in Binary • Therefore decimal numbers can be represented as digital and visa versa • A subscript number is used to indicate the number system being represented.

  5. Counting in Binary

  6. Hexadecimal Numbers • Base 16 number system • Hex meaning six, dec meaning ten • Simplify task of writing binary; “shorthand binary” • 8 digit binary number can be written as a two digit hexadecimal number • We need 16 unique symbols to represent the hexadecimal system, hence 0-9, A-F are used • Hexadecimal numbers are indicated by the subscript number 16 e.g. 6E16 • Alternatively…. &H6E

  7. Hexadecimal V Binary 100010102 = 8A16 001011102 = ? 111001012 = ?

  8. Hexadecimal to Decimal • In Hexadecimal, being a base 16 number system, powers of 16 provide the value of each column.

  9. Converting between hexadecimal, binary and decimal • Binary to decimal conversion 1101112 = 32 +16 + 0 + 4 + 2 + 1 = 5510 • Hexadecimal to decimal conversion 5C316 = (5 x 162) + (C x 161) + (3 x 160) = (5 x 256) + (12 x 16) + (3 x 1) = 1280 + 192 + 3 = 147510 • Decimal to Binary conversion • Method 1 subtraction & Method 2 repeated division

  10. Decimal to Binary conversion Binary equivalent of decimal 109 Method 1 Subtraction 109 -64 1 45 -32 1 11011012 = 10910 13 0 13 -8 Result from top to bottom 1 5 1 -4 1 0 1 -1 1 0

  11. Decimal to Binary conversion Binary equivalent of decimal 109 109 Method 1 Repeated Division ÷2 1 54 0 ÷2 27 11011012 = 10910 ÷2 1 13 Result from bottom to top ÷2 1 6 ÷2 0 3 ÷2 1 1 1 ÷2 0

  12. Character Representation • Characters must be represented using binary code if it is to be stored and processed by computers. • Two types of character require representation • Printable characters – A-Z,a-z, 0-9, punctuation marks and special symbols i.e. $, % • Non-printable characters or control characters • backspace, delete to remove data • Carriage returns and linefeed characters influence formatting • Acknowledge (ACK) and neg. acknowledge (NACK) characters are used in communication

  13. Character Representation • The TWO most common methods for coding characters into binary are: • ASCII (American Standard Code for Information Interchange) ass-kee • Used extensively on personal computers and for communication on the WWW. • EBCDIC (Extended Binary Coded Decimal Interchange Code) eb-sih-dik • Used extensively on large IBM computers

  14. ASCII Code • A seven bit code which means there are 128 different characters in the standard ASCII character set • Extensions to standard ASCII are in use: • Extended ASCII is used within MS-DOS • ANSI characters are used within Windows and Mac OS’s • ISO Latin 1 is an 8-bit system that includes ASCII (developed by ISO for use on WWW) • These systems use values above 127 to represent various foreign language, graphical and mathematical characters

  15. ASCII Code • Standard ASCII simplifies the process of sorting • Code for “A” = 65 and is less than the code for “B” = 66 • Code for “a” = 97 as each capital letter has a code which is 32 less than its lower case equivalent • A = 1000001 • a = 1100001

  16. Integer Representation Whole numbers, both positive and negative A subset of real numbers Positive integers and zero can easily be represented using binary, but what about representing negative integers Can’t use “-” as we can only work with 1 & 0 Two methods • Sign and Modulus • Two’s complement

  17. Sign and Modulus • Adds an extra bit to the front of each number to represent the sign of the number • 0 is positive • 1 is negative • Modulus is the magnitude of the number or absolute value e.g. 7 bits used to display number 12 = 00001100 -12 = 10001100

  18. Sign and Modulus • How do we represent zero? • Two ways 00000000 or 10000000 • Write the sign modulus for the following using 7 bits for the modulus: -27 = 10011011 15 00001111 = -75 11001011 = Sign Modulus method is not generally used on modern computers

  19. Two’s Complement Wrap to form a circle 0 250 500 750 1000 Moving to the left or anti-clockwise direction the integers decrease in value by -1,-2,-3; but it is represented by the numbers 999,998,997… These numbers are the complements of their positive equivalents 0 Moving to the right or clockwise direction the integers increase in value e.g. 1,2,3 + - 750 250 500

  20. Odometers Another way to look at two’s complement is to consider the odometer on a car. Imagine that the odometer moves backwards when the car is in reverse

  21. Two’s Complement • Therefore positive integers 0 to 499 and negative from 999 down to 500 • Addition -3 997 + -5 + 995 -8 1992 Discard the leading 1 we get the correct answer 992 or -8

  22. Two’s Complement -6 994 + 19 + 19 13 1013 Discard the leading 1 we get the correct answer 013 or 13

  23. Two’s Complement Binary odometer

  24. Two’s Complement Each positive number begins with a ‘0’ and each negative number begins with a ‘1’ Exchanging 1s for 0s and 0s for 1s almost results in the correct two’s complement, it is out by 1

  25. Two’s Complement To find the two’s complement of a number: • Write down the binary equivalent of the number. • Perform a one’s complement i.e. switch 1s for 0s and 0s for 1s • Add 1 to it. Value of 14 Eg. Two’s complement of -14 00001110 11110001 + 1 11110010

  26. Two’s Complement Lowest order bit Highest order bit

  27. Representation of Fractions and Real Numbers • Computers cannot represent all the possible real numbers precisely. It can work with approximations as we do. E.g. 1.33333 -> 1.3 -∞ +∞ 0 Negative Nos Positive Nos Too large Too large Too small Rounding Off 8.426759 = 8.42676 Truncation 8.426759 = 8.42675

  28. Representation of Fractions and Real Numbers • Need a system that will provide a satisfactory level of accuracy for the majority of applications. • There are two methods used for representing fractions: • Fixed Point • Floating Point

  29. Fixed Point • Refers to the position of the decimal point or in binary it is called the “radix point” • When using fixed point numbers the radix point remains in the same position for all numbers • E.g. a 16 bit fixed point system may have 8 bits for the whole number part and 8 bits for the fractional part • Problem is that very large numbers and very small numbers can’t be represented

  30. Fixed Point

  31. Floating Point • Floating point can be thought of as a generalised fixed point numbers • The position of the radix point is encoded within the format. In this way the radix point can be placed in a different position within a number • Number is stored using scientific notation 2345.678 can be written as 2.345678 x 103 which can be written as 2.345678E+3 • Three components to each number + 2.234567 x 103 sign mantissa exponent

  32. Floating Point • The value of the exponent determines the position of the radix point • Floating point system allows us to represent a much larger range of numbers using less storage space E.g. 0.000000000000000000000052 Can be written as +5.2E-23 • Working with floating point numbers, compared to integers, is a complicated and processor intensive process • Today’s microprocessors contain a special maths co-processor called a Floating Point Unit or FPU

  33. Floating Point • The Institute of Electrical and Electronics Engineers (IEEE) has produced a standard for representing binary numbers using the floating point system • Standard 754 specifies both a single precision format (using 32 bits) and a double precision format (using 64 bits) • All major hardware and software developers have accepted these standards

  34. IEEE 754 Single Precision Floating Point Standard • Requires 32 bits • First bit is the sign bit • Next 8 bits are used to store the exponent • Final 23 bits are the fractional part 1 11001010 00000000000000000011001 sign exponent mantissa -1.11001 x 21101 0 = +ive1 = -ive Same as original number but with the leading 1 ignored Its decimal value of 13 plus 127

  35. IEEE 754 Single Precision Floating Point Standard • Largest number in binary 2 x 2127 or 2128 On a calculator, in decimal that equates to -3.4 x 1038 to 3.4 x 1038

  36. IEEE 754 Single Precision Floating Point Standard Special Cases *used for meaningless operations such as division by zero and square roots of negative numbers

  37. IEEE 754 Double Precision Floating Point Standard • Uses 64 bits to represent each number • A sign bit • 11 bits for the exponent • 52 bits for the mantissa

  38. Binary Arithmetic - Addition • Perform the operation similarly to decimal numbers • Starting with the RHS add the column and if the result is 10 or 11 ‘carry’ the 1 to the next column

  39. Binary Arithmetic - Addition 1 1 1 1 1 1 1 1 1 1 01010111 + 01011101 + 11000000 + 00011100 01110100 01110000 0 1 1 1 0 0 1 1 1 1 0 1 0 0 0 1 0 0 1 1 0 0 0 0 This result is a negative number in 8 bit two’s complement, as the leading bit is one. How come? The addition in decimal is 93 + 116 = 209 But 209 is outside the range of values available in 8 bit two’s complement. The result has wrapped around into the negatives This results in a carry in the final stage of the addition. As we only have 8 bits to work with we ignore this last carry

  40. Binary Arithmetic - Subtraction • Computers do not subtract, but they do add negative numbers • i.e 5 – 3 is the equivalent of 5 + (-3) • Hence all subtractions are additions • In Two’s Complement we convert the number being subtracted to its two’s complement form and then add 1 1 1 – 01010111 01010111 + becomes 11100100 00011100 0 0 1 1 1 0 1 1

  41. Binary Arithmetic - Subtraction 1 00011001 - 00011001 + becomes 11111011 00000101 0 0 0 1 1 1 1 0 25 – (-5) 25 + 5 = 30

  42. Binary Arithmetic - Multiplication • Multiplication in binary is the same as that in decimal but we only have two digits to be concerned with • Used the “Shift and add” method 1001 x 1001 x 111 101 1001 1001 10010 00000 100100 100100 111111 101101

  43. Binary Arithmetic - Multiplication • A microprocessor need not know how to multiply if it is able to shift bits to the left and it can add • 8086 chip has assembler instructions including SAL “Shift Arithmetic Left” and SAR “Shift Arithmetic Right” used in conjunction with the addition instructions ADD (addition) and ADC (addition with carry) • All microprocessors have the equivalent of these instructions “hardwired” as part of their micro-code instruction set

  44. Binary Arithmetic - Division 1 0 0 1 1 1 0 1 1 1 0 1 0 1 1 0 58 / 6 = 9 r 4 1 0 1 0 1 1 0 1 0 0

  45. Binary Arithmetic - Division • Most complex of the four operations • One method involves using partial fractions • Another method uses a “shift and subtract” technique

  46. 2003 HSC Question • Explain how a fraction is represented in single precision floating point binary representation. (ii) Convert the decimal number 45 (ie 4510) to a hexadecimal number. (iii) Using four-bit binary representation and two’s complement, perform the following subtraction: 1110–0111.

  47. Electronic Circuits to Perform Standard Software Operations • Electronic circuit – a circular path along which electrons (electricity) can flow. The circuit must be complete for this to occur. • Logic Gate – an electronic circuit that transforms inputs into outputs based on strict logical rules • Integrated circuits are made up of combinations of logic gates

  48. Logic Gates Logic gates are electric circuits that produce a true or false value (1 or 0 output signal) depending upon the input requirements of the circuit. They are usually implemented in the computer using integrated circuits; a small silicon chip containing components such as resistors, diodes, transistors, and capacitors.

More Related