1 / 43

Data Representation, Number Systems and Base Conversions

Data Representation, Number Systems and Base Conversions. Chapter Outline. Numeric data representation systems Binary, octal, and hexadecimal Non-numeric data representation ASCII and EBCDIC, UNICODE Representation of numbers Integers, floating point and Binary coded decimal

karlyn
Download Presentation

Data Representation, Number Systems and Base Conversions

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. Data Representation, Number Systems and Base Conversions Computer Orgn & Arch 2011

  2. Chapter Outline • Numeric data representation systems • Binary, octal, and hexadecimal • Non-numeric data representation ASCII and EBCDIC, UNICODE • Representation of numbers • Integers, floating point and Binary coded decimal • Number base conversions Computer Orgn & Arch 2011

  3. Number systems and computers • The BINARY number system is a positional number system with similar properties to the decimal system. • However, we often need to convert binary to a number system we are familiar with (decimal) or a system that is easier for humans to use. • Computer programs and data are often represented using octal and hexadecimal number systems because they are a short hand way of representing binary numbers. Computer Orgn & Arch 2011

  4. Binary presentation of data • Sometimes binary numbers need to be converted to Hexadecimal (hex) numbers which reduces a long string of binary digits to a few hexadecimal characters. This makes it easier to remember and to work with the numbers. Computer Orgn & Arch 2011

  5. Numeric Data representation Deals with the representation of numbers in a computer. In digital computers, the most commonly used number systems are: • binary • octal • hexadecimal Number System Radix (base) Digits used Decimal 10 0, 1, .....,9 Binary 2 0, 1 Octal 8 0, 1, ......, 7 Hexadecimal 16 0, 1, ..., 9, A, B, ..., Computer Orgn & Arch 2011

  6. There are three Numbers formats in computer world. • Integer or fixed point format • Floating point format • Binary Coded Decimal format (BCD) Computer Orgn & Arch 2011

  7. Numeric Data representation Numeric data can be • Integers - fixed-point numbers (no fractional part) • Unsigned integers. the standard binary encoding already given. Supports only positive values • Signed Magnitude integers.This is another way or representing negative integers. Involves treating the most significant (left most) bit in the word as a sign bit .Positive-0, negative -1. example: 4 bits, 0101 is 5 &1101 is -5 • Floating-point numbers - numbers with fractional components Computer Orgn & Arch 2011

  8. Binary Coded Decimal • When data is entered , it must be converted into some binary form before processing can begin. This is called BCD • In BCD, each figure of the number to be coded is represented by its 4 bits binary equivalent • Example 8159=1000 0001 0101 1001

  9. There are two BCD formats; Packed(condensed) and Extended(unpacked) Computer Orgn & Arch 2011

  10. Formats • Packed, each figure occupies half a byte. Eg 341= 0011 0100 0001 • Unpacked, each decimal figure is represented by a byte. Eg 341=00000011 00000100 00000001 • Hardware designed for BCD is more complex than that for binary formats • Advantage, its closer to the alphanumeric codes.

  11. Number Base Conversions Two techniques available: • Repeated division • Bit grouping Computer Orgn & Arch 2011

  12. Number Base Conversions (Cont) Repeated Division Technique To convert a number in base  to the equivalent number in base , divide the given number by base  using base  arithmetic. Computer Orgn & Arch 2011

  13. Number Base Conversions (Cont) Bit Grouping Technique Employed for conversion between octal and binary and for the conversion between hexadecimal and binary. Each hexadecimal digit corresponds to a group of four binary bits. Each octal digit corresponds to a group of three binary bits. Computer Orgn & Arch 2011

  14. Number Base Conversions (Cont) Binary to Octal and Octal to Binary To convert a binary number to octal, simply split up the binary number into 3-bit groups starting from the least significant bit and get the corresponding octal digits. Qn . Convert 1001101 to octal . 1001101.0111 to octal To convert an octal number to binary, for each octal digit, get the equivalent 3-bit binary representation. Computer Orgn & Arch 2011

  15. Number Systems - Hexadecimal • The hexadecimal system is a base-16 system. It contains the digits 0 to 9 and the letters A to F. The letters A to F represent the decimal numbers 10 to 15. Computer Orgn & Arch 2011

  16. Number Systems - Hexadecimal • Conversion to binary is done the same way as octal to binary, but binary digits are organized into groups of 4. • Conversion from binary to hexadecimal involves breaking the bits into groups of 4 and replacing them with the hexadecimal equivalent. Computer Orgn & Arch 2011

  17. HEX BINARY 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 A 1010 B 1011 C 1100 D 1101 E 1110 F 1111 Hexadecimal - Binary conversions Hex to binary: (Bit group repeating) 1D7F16 = 0001 1101 0111 11112 5AB216 = 0101 1010 1011 00102 Binary to hex: 1110 0011 0000 11002 = E30C16 1001 1000 1101 11112= 98DF16 Computer Orgn & Arch 2011

  18. Number Base Conversions (Cont) Binary to hex and hex to binary To convert a binary number to hexadecimal, simply split up the binary number into 4-bit groups starting from the least significant bit and get the corresponding hexadecimal digits. Qn. Convert 1001101 to Hex. To convert a hexadecimal number to binary, for each hexadecimal digit, get the equivalent 4-bit binary representation. Computer Orgn & Arch 2011

  19. Octal 0 1 2 3 4 5 6 7 Binary 000 001 010 011 100 101 110 111 Number Systems - Octal • An octal number can easily be converted to binary by replacing each octal digit with the corresponding group of 3 binary digits. Computer Orgn & Arch 2011

  20. Data representation • Human brain can process large variety of data including: • characters • numbers • images and sounds • touch, smell and taste • Current technology limits data that computer can efficiently manipulate to numeric data. Therefore, ALL data - no matter how complex - must be represented (encoded) in the computers memory in numeric form. Computer Orgn & Arch 2011

  21. Data Representation • Computers represent data using binary numbers because: • It is easy to represent binary numbers as electrical states or signals which can be processed by two-state (on-off) electrical devices (eg transistors) • . Standardization; organizations have created standard data encoding methods for communication among computer systems and their components. Computer Orgn & Arch 2011

  22. Number Systems - Decimal • The decimal system is a base-10 system. There are 10 distinct digits (0 to 9) used to represent any quantity. • For an n-digit number, the value that each digit represents depends on its weight or position. The weights are based on powers of 10. 4TH. 3RD. 2ND. 1ST. POSITION 103 = 1000 102 = 100 101 = 10 100 = 1 WEIGHT For example, 491610 = 4*1000 + 9*100 + 1*10 +6*1 Computer Orgn & Arch 2011

  23. Base 10 number systems • Base 10 uses the ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 which are combined to represent all possible numeric values.  • The decimal number system is based on powers of 10. Each column position of a value, from right to left, is multiplied by the number 10, which is the base number, raised to a power, which is the exponent. The power that 10 is raised to depends on its position to the left of the decimal point. Computer Orgn & Arch 2011

  24. 8TH 7TH 6TH 5TH 4TH 3RD 2ND 1ST POSITION 27=128 26=64 25=32 24=16 23=8 22=4 21=2 20=1 WEIGHT Number Systems - Binary • The binary system is a base-2 system. There are 2 distinct digits (0 and 1) to represent any quantity. • For an n-digit number, the value that each digit represents depends on its weight or position. The weights are based on powers of 2. • For example: 110100102 = 1*128 + 1*64 + 0*32 + 1*16 + • 0*8 + 0*4 + 1*2 +0*1 = 21010 Computer Orgn & Arch 2011

  25. Converting decimal numbers to 8-bit binary numbers Example: Convert the binary number 01110000 to a decimal number. Note: Work from right to left. Remember that anything raised to the 0 power is 1. Therefore 20 = 1 0 x 20 = 00 x 21 = 0 0 x 22 = 0 0 x 23 = 01 x 24 = 161 x 25 = 32 1 x 26 = 64 +0 x 27= 0––––––––––– 112 Computer Orgn & Arch 2011

  26. Number Systems - Octal • Octal and hexadecimal systems provide a shorthand way to deal with the long strings of 1’s and 0’s in binary. • Octal is a base-8 system using the digits 0 to 7. To convert to decimal, you can again use a weighted system eg. • 75128 = 7*83 + 5*82 + 1*81 + 2*80 = 391410 • To convert to decimal, you can again use a weighted system.3216 = ? Computer Orgn & Arch 2011

  27. Decimal to Base-n Conversions • To convert from decimal to a different number base such as octal, binary or hexadecimal involves repeated division by that number base. • Keep dividing until the quotient is zero • Use the remainders in reverse order Computer Orgn & Arch 2011

  28. Decimal to Base-n Conversions Decimal to OctalDecimal to Hex 8 |674 16 |735 8 |84 2 (*80) 16 |45  F (*160) 8 |10 4 (*81) 16 | 2 D (*161) 8 | 1  2 (*82) 16 | 0 2 (*162) 8 | 0  1 (*83) 0 0 Answer: 12428 Answer: 2DF16 Computer Orgn & Arch 2011

  29. Computer Orgn & Arch 2011

  30. Adding numbersSo to add the numbers 0610=01102 and 0710=01112 (answer=1310=11012) we can write out the calculation DecimalUnsigned Binary1 (carry) 06+07 13 110 (carry) 0110+0111 1101 Computer Orgn & Arch 2011

  31. Multiplying number DecimalBinary For example,00101001 × 00000110 = 111101100  0  1  0  1  0  0  1 = 41 (base10)× 0  0  0  0  0  1  1  0 = 6 (base 10)0  0  0  0  0  0  0  00  0  1  0  1  0  0  1   0  0  1  0  1  0  0  1      0  0  1  1  1  1  0  1  1  0 = 246 (base 10) Computer Orgn & Arch 2011

  32. Rules of Binary Subtraction0 - 0 = 0 0 - 1 = 1, and borrow 1 from the next more significant bit 1 - 0 = 1 1 - 1 = 0 For example,00100101 - 00010001 = 00010100        0borrows  0  0  110  0  1  0  1 =37 (base10)- 0  0  0 1  0  0  0  1 =17 (base 10)0  0  0 1  0  1  0  0 =20 (base10) Computer Orgn & Arch 2011

  33. Non-numeric Data Representation Alphanumeric codes are used when the computing device has to handle letters and special symbols as well as decimal digits. Two dominant coding schemes are: • ASCII (American Standard Code for Information Interchange) • EBCDIC (Extended Binary Coded decimal Interchange Code) Computer Orgn & Arch 2011

  34. Alphanumeric Codes • There are three main coding methods in use: • The American Standard Code for Information Interchange (ASCII) • Extended Binary Coded Decimal Interchange Code (EBCDIC) • Unicode. Computer Orgn & Arch 2011

  35. Alphanumeric Data • Alphanumeric (character) data such as names and addresses are represented by assigning a unique binary code or sequence of bits to represent each character. As each character is entered from a keyboard (or other input device) it is converted into its binary code. Computer Orgn & Arch 2011

  36. Alphanumeric Data • Character code sets contain two classes of codes: • Printable (normal characters) • Non-printable ie. characters used as control codes. For example: • CTRL G • CTRL Z . • Most computers use ASCII codes to represent text, which makes it possible to transfer data from one computer to another. • ASCII (128 characters) Computer Orgn & Arch 2011

  37. ASCII • ASCII • 7-bit code (128 characters) • has an extended 8-bit version • used on PC’s and non-IBM mainframes • Was widely used to transfer data from one computer to another – now being replaced by Unicode Computer Orgn & Arch 2011

  38. ASCII • ASCII is a code for representing English characters as numbers, with each letter assigned a number from 0 to 127. • Each character has a unique pattern of eight binary digits assigned to represent it. Computer Orgn & Arch 2011

  39. An ASCII subset • “CAB” = 43414216 • = 0100 0011 0100 0001 0100 00102 • “F1” = 463116 • = 0100 0110 0011 00012 • “3415” = 3334313516 • = 0011 0011 0011 0100 0011 0001 • 0011 01012 • *Note that this is a text string and no arithmetic may be done on it. A postcode is a good example of storing numbers as text. Symbol Code A 41 B 42 C 43 D 44 E 45 F 46 0 30 1 31 2 32 3 33 4 34 5 35 6 36 7 37 ASCII Coding Examples Computer Orgn & Arch 2011

  40. Alphanumeric Codes • EBCDIC • an 8-bit code (256 characters) • used on mainframe IBM machines. • The binary code for text as well as communications and printer control from IBM • Both ASCII and EBCDIC are inadequate for representing all international characters. eg Chinese characters Computer Orgn & Arch 2011

  41. Alphanumeric Codes • Unicode - recent 16 bit standard - can represent 65 thousand characters, of which 49,000 have been defined, incorporates ASCII-7 as subset. Computer Orgn & Arch 2011

  42. Both of those are 1 byte per character. ( ASCII & EBCDIC)Unicode is a coding where characters require 2 bytes per character. • Windows can use unicode, but it is not required.It is useful if extra characters not supported in the 1 byte character sets are needed in the same document. Computer Orgn & Arch 2011

  43. Representing Images • Two popular techniques used • Bitmap techniques .  image composed of pixels is known as a bitmapped image  • Vector techniques. • Vector graphics is the use of geometrical primitives such as points, lines, curves, and shapes or polygon(s), which are all based on mathematical equations, to represent images in computer graphics. Computer Orgn & Arch 2011

More Related