The representation of data within the computer

Similar documents
The string of digits in the binary number system represents the quantity

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Systems I: Computer Organization and Architecture

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

2011, The McGraw-Hill Companies, Inc. Chapter 3

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Lecture 2. Binary and Hexadecimal Numbers

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Chapter 1: Digital Systems and Binary Numbers

Binary Numbers. Binary Octal Hexadecimal

Useful Number Systems

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Binary Representation

Base Conversion written by Cathy Saxton

Solution for Homework 2

2 Number Systems. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Computer Science 281 Binary and Hexadecimal Review

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Chapter 4: Computer Codes

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Numbering Systems. InThisAppendix...

CPEN Digital Logic Design Binary Systems

Number Representation

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

COMPSCI 210. Binary Fractions. Agenda & Reading

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

The use of binary codes to represent characters

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Number Systems and Radix Conversion

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

Chapter 1. Binary, octal and hexadecimal numbers

CSI 333 Lecture 1 Number Systems

NUMBER SYSTEMS. 1.1 Introduction

3. Convert a number from one number system to another

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Chapter 5. Binary, octal and hexadecimal numbers

Counting in base 10, 2 and 16

Section 1.4 Place Value Systems of Numeration in Other Bases

HOMEWORK # 2 SOLUTIO

Encoding Text with a Small Alphabet

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

Chapter 2. Binary Values and Number Systems

Number and codes in digital systems

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Number Systems. Introduction / Number Systems

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

The Answer to the 14 Most Frequently Asked Modbus Questions

A Step towards an Easy Interconversion of Various Number Systems

The Unicode Standard Version 8.0 Core Specification

THE BINARY NUMBER SYSTEM

CS321. Introduction to Numerical Methods

Decimal to Binary Conversion

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

Lecture 8: Binary Multiplication & Division

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

MEP Y9 Practice Book A

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Lecture 11: Number Systems

Binary, Hexadecimal, Octal, and BCD Numbers

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Numeration systems. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

=

DNA Data and Program Representation. Alexandre David

PROBLEMS (Cap. 4 - Istruzioni macchina)

The Hexadecimal Number System and Memory Addressing

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

NUMBER SYSTEMS. William Stallings

CHAPTER 5 Round-off errors

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

Pemrograman Dasar. Basic Elements Of Java

Memory is implemented as an array of electronic switches

ASCII Characters. 146 CHAPTER 3 Information Representation. The sign bit is 1, so the number is negative. Converting to decimal gives

The programming language C. sws1 1

CS201: Architecture and Assembly Language

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Logic Reference Guide

Addition Methods. Methods Jottings Expanded Compact Examples = 15

Click on the links below to jump directly to the relevant section

Positional Numbering System

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points.

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory.

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Activity 1: Using base ten blocks to model operations on decimals

So far we have considered only numeric processing, i.e. processing of numeric data represented

Binary Adders: Half Adders and Full Adders

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

EURESCOM - P923 (Babelweb) PIR.3.1

Data Storage. 1s and 0s

Intel Hexadecimal Object File Format Specification Revision A, 1/6/88

MACHINE INSTRUCTIONS AND PROGRAMS

MATH-0910 Review Concepts (Haugen)

Digital codes. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

Transcription:

The representation of data within the computer Digital and Analog System of Coding Digital codes. Codes that represent data or physical quantities in discrete values (numbers) Analog codes. Codes that represent data in a continuous form. They are more difficult to interpret than digital codes but they are more gradual. Example of digital device Vs analog device: Traditional watch with an hour hand and a minute hand revolving Vs digital watch. Number systems Under different number systems, quantities may be represented in different ways. Different number systems have different numbers of digit symbols. Each digit in a number has its values. Decimal (Denary) It is the most familiar one. It originated from counting numbers by fingers. 10 digit symbols (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and each digit has a place value in a power of 10. e.g. 428 10 : digit 8 has a place value 10 0 digit 2 has a place value 10 1 digit 4 has a place value 10 2 Binary The number of meaningful electronic states is only two An electronic pulse is on or off. The most natural coding for computer is binary. The binary number system has only 2 digit symbols, i.e. 0 and 1, with place values in power of 2. Conversions Octal From binary to decimal, 101110 2 = 1* 2 5 + 0 * 2 4 + 1 * 2 3 + 1 * 2 2 + 1 * 2 1 + 0 * 2 0 = 46 10 From decimal to binary, 2 46 2 23... 0 2 11... 1 2 5... 1 2 2... 1 1... 0 Therefore, the result is 101110 2. Programming in binary is however very tedious and prone to error. The octal system is used as it makes programming simpler (closer to 10) and not very difficult for the computer (easy conversion between binary and octal). DATA REPRESENTATION Page 1

This system has 8 digit symbols (0 to 7) and each digit has a place value in powers of 8. Knowing the place values, we can convert octal to decimal and vice versa. 243 8 = 2*8 2 + 4*8 1 + 3*8 0 = 163 10 8 163 8 20...3 2...4 CH/NSSICT/Feb., 2013. i.e. 243 8 Conversions between octal and binary numbers are much simpler, just grouping the binary codes 3 in a group and then change each group into an octal digit. e.g. 010 101 001 2 = 251 8 Hexadecimal The octal number system has a disadvantage in coding computer instructions. Computers work in twos, or power of 2, thus it is not efficient for them to deal with numbers in 3-bit groups. A new number system, the hexadecimal system, is developed with 16 digit symbols (0-9, A-F) and each hexadecimal digit is equivalent to a 4-digit binary number. Table represent numbers of different number system Decimal Binary Hexadecimal Decimal Binary Hexadecimal 0 0000 0 8 1000 8 1 0001 1 9 1001 9 2 0010 2 10 1010 A 3 0011 3 11 1011 B 4 0100 4 12 1100 C 5 0101 5 13 1101 D 6 0110 6 14 1110 E 7 0111 7 15 1111 F Conversions between hexadecimal and binary, and hexadecimal and decimal are similar to those of octal. Conversions between octal and hexadecimal are done by first converting the number to binary. Simple Arithmetic on Binary Number Addition Subtraction Multiplication 11 11 11 11 + 101 + 101 + 101 + 101 0 00 000 1000 1010 1010 1010-101 - 101-101 1 01 101 Division 110 110 * 101 101 )11110 11000 101 110 1010 11110 1010 DATA REPRESENTATION Page 2

Number Representation inside the computer Sign-and-magnitude representation If we use 8 bits (one bit means one 1 or one 0 ) to store an integer, the 1st bit is reserved as a sign bit ( 1 for -ve, 0 for +ve) and the rest are used to represent the magnitude. and 0 1 0 1 0 1 0 1 = (64+16+4+1) sign 64 32 16 8 4 2 1 = 85 10 1 0 1 0 1 0 1 1 = -(32+8+2+1) sign 64 32 16 8 4 2 1 = -43 10 1's Complement representation Under 1's complement representation, all the negative numbers are represented by replacing all the digits to their complements. (i.e. 0 to 1, 1 to 0) The first digit can still be regarded as sign bit. 2 s Complement representation Two steps to represent a negative number: Step 1 : change from its positive value to its 1 s complement. Step 2 : add 1 to the last digit and take care of the carry. e.g. -91 10 = -1011011 2 (binary value) = 10100100 (1 s complement) = 10100101 (2 s complement) -91 10 is represented as 10100101 in 2 s complement. Advantages i. complement operation is easy ii. no need to place sign bit explicitly iii. easy to perform addition and subtraction iv. no redundancy representation to 0 (in 8-bit sign-and-magnitude representation, both 00000000 and 10000000 represent zero) Subtraction between 2 s complement integer. for A - B, (same as A + (-B)) step 1 : change B to its 2 s complement step 2 : adding the result to A step 3 : ignore the extra digit in front of the resulting number (if necessary) e.g. 01110111-01010001 (i.e. 119 10-81 10 ) step 1 : 2 s complement of 01010001 = 10101111 step 2 : 01110111 + 10101111 = 100100110 step 3 : ignore the extra bit, the result is 00100110 (i.e. 38 10 ) DATA REPRESENTATION Page 3

Exercise Convert the following into 8-bit with 2 s complement representation as negative number. i. -125 10 = -01111101 (binary value) ii. 67 10 = 01000011 (binary value) = 10000010 (1 s comp.) = (1 s comp.) = 10000011 (2 s comp.) = (2 s comp.) iii. -93 10 = -01011101 (binary value) iv. 88 10 = 01011000 (binary value) = 10100010 (1 s comp.) = 10100011 (2 s comp.) Using the representation in part i to calculate the following binary arithmetic expressions i. 99 10-71 10 99 10 = 01100011-71 10 = -01000111 (binary value) = 10111000 (1 s comp.) = 10111001 (2 s comp.) 99 10-71 10 = ( 01100011 ) 2 + ( 10111001 ) 2 = 100011100 (discarding leading zero) = 28 10 ii. 88 10-121 10 88 10 = 01011000-121 10 = -01111001 (binary value) = 10000110 (1 s comp.) = 10000111 (2 s comp.) 88 10-121 10 = 01011000 2 + 10000111 2 = 11011111 (2 s comp.) = 11011110 (1 s comp.) = -100001 2 = -33 10 Convert the following bit pattern using the representation in part i into decimal integers: i. 11011011 = 11011010 (1 s comp.) ii. 10011101 = 10011100 (1 s comp.) = -00100101 2 (binary value) = -01100011 2 (binary value) = -37 10 = -99 iii. 01101110 = 110 10 iv. 11101110 = 11101101 (1 s comp.) = -10010 (binary value) What is the maximum value and minimum value of such an integer? = -18 10 Maximum representation : 01111111 = 2 7 1 = 127 10 Minimum representation : 10000000 = 01111111(1 s comp.) = -10000000 2 = -2 7 = -128 10 DATA REPRESENTATION Page 4

Data representation of binary fraction Interconversion between binary and decimal fraction Sample conversion from binary to decimal fraction: 101010.01011 2 = 2 5 + 2 3 + 2 1 + 2-2 + 2-4 + 2-5 = 42.6875 10 Sample conversion from decimal fraction, e.g. 22.843375 10, using repeated multiplication: 0.84375 0.6875 1 0.375 1 0.75 0 0.5 1 0.0 1 0.84375 10 = 0.11011 2 and 22.84375 10 = 10110 2 + 0.11011 2 = 10110.11011 2 Range and Accuracy Range The range is the set of all numbers that can be represented by a particular system. e.g. for the 8-bit integer, the range using 2 s complement is -128 to 127. Accuracy. This is a measure of the closeness of an approximation to the exact or true value. Precision. This is the term associated with the word length, i.e. available to represent a given number. e.g. Suppose that we have to i. represent the number 7 in pure binary using four digits, i.e. 0111, ii. represent 0.10101010101 in 8 bits fixed point, i.e. 0.10101010. Then the first one is more accurate and the second representation is more precise. Resolution. This is simply the magnitude of the difference between the last tow two adjacent digits or numbers. DATA REPRESENTATION Page 5

Limitation of number system Overflow and Underflow error Every number representation has its own range so that every number in the system fall inside the range. A value of the result from an arithmetic operation which is larger than the upper limit of the range of the system will cause an overflow error. On the other hand, if the value is too small to be represented by the number of bit, it will cause an underflow error. Rounding errors After certain calculation (e.g. multiplication and division), the number of significant figures of the resulting value may be too large to be hold by the number of bits. Round becomes necessary. Conversion errors Error may be evolved from conversions. REVISION e.g. 0.4 10 0.01100110 2 = 0.3984375 10 i. Convert the following into 11-bit with 2 s complement representation as negative number. a. -567 10 b. 999 10 c. 93 10 d. -88 10 10111001001 01111100111 00001011101 111101010000 ii. Using the representation in part i to calculate the following binary arithmetic expressions a. 888 10-771 10 b. 29 10-111 10 = 01101111000+10011111101=00001110101=117 10 = 00000011101+111100100001=11110101110=-82 10 iii. Convert the following bit pattern using the representation in part i into decimal integers: a. 1010110001 b. 1111001111 c. 0101010111 d. 1011000000-335 -49 343-320 DATA REPRESENTATION Page 6

Character Set Characters also stored as binary code in computer. Usually, one character is stored in 1 byte, so there can be 256 different characters. The most common character set used in computer is the American Standard Coding for Information Interchange (ASCII). Decimal Binary Hexa. Code Character Decimal Binary Hex Character Code Code Code Code a. Code 32 00100000 20 (space) 80 01010000 50 P 33 00100001 21! 81 01010001 51 Q 34 00100010 22 " 82 01010010 52 R 35 00100011 23 # 83 01010011 53 S 36 00100100 24 $ 84 01010100 54 T 37 00100101 25 % 85 01010101 55 U 38 00100110 26 & 86 01010110 56 V 39 00100111 27 ' 87 01010111 57 W 40 00101000 28 ( 88 01011000 58 X 41 00101001 29 ) 89 01011001 59 Y 42 00101010 2A * 90 01011010 5A Z 43 00101011 2B + 91 01011011 5B [ 44 00101100 2C 92 01011100 5C \ 45 00101101 2D - 93 01011101 5D ] 46 00101110 2E. 94 01011110 5E ^ 47 00101111 2F / 95 01011111 5F _ 48 00110000 30 0 96 01100000 60 ` 49 00110001 31 1 97 01100001 61 a 50 00110010 32 2 98 01100010 62 b 51 00110011 33 3 99 01100011 63 c 52 00110100 34 4 100 01100100 64 d 53 00110101 35 5 101 01100101 65 e 54 00110110 36 6 102 01100110 66 f 55 00110111 37 7 103 01100111 67 g 56 00111000 38 8 104 01101000 68 h 57 00111001 39 9 105 01101001 69 i 58 00111010 3A : 106 01101010 6A j 59 00111011 3B ; 107 01101011 6B k 60 00111100 3C < 108 01101100 6C l 61 00111101 3D = 109 01101101 6D m 62 00111110 3E > 110 01101110 6E n 63 00111111 3F? 111 01101111 6F o 64 01000000 40 @ 112 01110000 70 p 65 01000001 41 A 113 01110001 71 q 66 01000010 42 B 114 01110010 72 r 67 01000011 43 C 115 01110011 73 s 68 01000100 44 D 116 01110100 74 t 69 01000101 45 E 117 01110101 75 u 70 01000110 46 F 118 01110110 76 v 71 01000111 47 G 119 01110111 77 w 72 01001000 48 H 120 01111000 78 x 73 01001001 49 I 121 01111001 79 y 74 01001010 4A J 122 01111010 7A z 75 01001011 4B K 123 01111011 7B { 76 01001100 4C L 124 01111100 7C 77 01001101 4D M 125 01111101 7D } 78 01001110 4E N 126 01111110 7E ~ 79 01001111 4F O 127 01111111 7F (del) DATA REPRESENTATION Page 7

Chinese Text Processing Under a Chinese text system, we can operate the computer with Chinese characters. That means we can use the computer to i. store the character which represented by certain codes (internal code). ii. use the English keyboard to input Chinese characters (input method). iii. display the Chinese characters in different shapes (graphical composition of Chinese characters of different fonts). All these features are provided by the Chinese operating system. (Windows XP) Character set In an English processing system, the internal code of a character may be an ASCII code. E.g. A s internal code is 01000001. In a Chinese processing system, the internal code may be the Chinese National Standard Codes for Information Interchange, Big 5 or other codes. (The internal code used in Chinese Windows is Big 5.) In an English processing system, the character set includes the alphabets ( a to z, and A to Z ), numerals ( 0 to 9 ) and symbols, such as $, &,?, #, *, etc, having over 200 characters in total. In a Chinese processing system, the character set includes all characters in an English processing system and all the commonly used Chinese characters, over 10000 in total. The character set is much larger and thus two bytes are used to store a single Chinese character. (Double Byte Character Set, DBCS). Big-5. i. For Traditional Chinese characters ii. iii. Regions: Taiwan, Hong Kong and Malaysia HK government has developed an extension to the set. (Hong Kong Supplementation Character Set). GuoBiao (GB). i. For Simplified Chinese characters ii. Regions: China, Singapore and Malaysia. Unicode consists of 20902 CJK (Chinese, Japanese and Korean) characters. Thus Simplified Chinese characters, Traditional Chinese characters and Japanese characters can be identified in the same document. Unicode. It contains the characters from the world s alphabets, ideographs and symbols. Its first 256 codes are the same as that of ASCII. The latest version, Unicode 6.2, contains 99020 graphic and format characters. One character may be stored in 1 byte, 2 bytes or 4 bytes. ۍ DATA REPRESENTATION Page 8