Computer Math CPS120 Introduction to Computer Science Lecture 4.

Slides:



Advertisements
Similar presentations
A digital system is a system that manipulates discrete elements of information represented internally in binary form. Digital computers –general purposes.
Advertisements

Chapter 2 : Number System
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Data Representation Computer Organization &
Data Representation COE 205
Level ISA3: Information Representation
Signed Numbers.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Data Representation ICS 233
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
1 CSE-221 Digital Logic Design (DLD) Lecture-1: Digital Systems & Number Systems.
Digital Fundamentals Floyd Chapter 2 Tenth Edition
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
1.6 Signed Binary Numbers.
Dr. Bernard Chen Ph.D. University of Central Arkansas
CPS120: Introduction to Computer Science Lecture 8.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Numbering systems.
Computers Organization & Assembly Language
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
1 Digital Technology and Computer Fundamentals Chapter 1 Data Representation and Numbering Systems.
CPS120: Introduction to Computer Science Midterm Exam Review.
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
EE2174: Digital Logic and Lab Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 2 Number.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Number Systems Spring Semester 2013Programming and Data Structure1.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
Number systems & Binary codes MODULE 1 Digital Logic Design Ch1-2 Outline of Chapter 1  1.1 Digital Systems  1.2 Binary Numbers  1.3 Number-base Conversions.
Introduction to Computer Science 1 With Examples in Visual Basic, C, C++, and Java 1 Mata-Toledo, Ramon A. & Cushman, Pauline K. McGraw-Hill,
1 EENG 2710 Chapter 1 Number Systems and Codes. 2 Chapter 1 Homework 1.1c, 1.2c, 1.3c, 1.4e, 1.5e, 1.6c, 1.7e, 1.8a, 1.9a, 1.10b, 1.13a, 1.19.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
CPS120: Introduction to Computer Science Computer Math: Converting to Decimal.
1 IT 231, CMPE 331 Digital Logic Design Week 2 Number systems and arithmetic.
Operations on Bits Arithmetic Operations Logic Operations
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
Computer Math CPS120: Lecture 3. Binary computers have storage units called binary digits or bits: Low Voltage = 0 High Voltage = 1 all bits have 0 or.
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
AEEE2031 Data Representation and Numbering Systems.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
SAK Chapter 21 Chapter 2 : Number System 2.1 Decimal, Binary, Octal and Hexadecimal Numbers 2.2 Relation between binary number system with other.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
CPS120: Introduction to Computer Science Midterm Exam Review.
MECH1500 Chapter 3.
Computer Math CPS120: Binary Representations. Binary computers have storage units called binary digits or bits: Low Voltage = 0 High Voltage = 1 all bits.
Chapter 1: Binary Systems
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
CPS120: Introduction to Computer Science Computer Math: Addition and Subtraction.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
Computer Math CPS120 Introduction to Computer Science Lecture 7.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Binary Numbers The arithmetic used by computers differs in some ways from that used by people. Computers perform operations on numbers with finite and.
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
Cosc 2150: Computer Organization
Lec 3: Data Representation
3.1 Denary, Binary and Hexadecimal Number Systems
Digital Systems and Number Systems
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Chapter Four Data Representation in Computers By Bezawit E.
Presentation transcript:

Computer Math CPS120 Introduction to Computer Science Lecture 4

Memory Units 1 nibble 1 byte 1 word 1 long word 1 quad word 1 octa-word 4 consecutive bits 8 consecutive bits 2 consecutive bytes 4 consecutive bytes 8 consecutive bytes 16 consecutive bytes

Larger Units of Memory 1 Kilobyte 1 Megabyte 1 Gigabyte 1 Terabyte 1 Petabyte 1 Exabyte 1024 bytes ~10 6 bytes ~10 9 bytes ~10 12 bytes ~10 15 bytes ~10 18 bytes 32 Mb = 32*10 3 Kb = 32 * 10 3 *1024 bytes = 32,768,000 bytes

Representing Data The computer knows the type of data stored in a particular location from the context in which the data are being used; i.e. individual bytes, a word, a longword, etc Bytes: 99 (10, 101 (10, 68 (10, 64 (10 Two byte words: 25,445 (10 and 17,472 (10 Longword: 1,667,580,992 (10

Alphanumeric Codes American Standard Code for Information Interchange (ASCII) 7-bit code Since the unit of storage is a bit, all ASCII codes are represented by 8 bits, with a zero in the most significant digit H e l l o W o r l d C 6C 6F F 72 6C 64 Extended Binary Coded Decimal Interchange Code (EBCDIC)

Number Systems We use the DECIMAL (10 system Computers use BINARY (2 or some shorthand for it like OCTAL (8 or HEXADECIMAL (16

Codes Given any positive integer base (RADIX) N, there are N different individual symbols that can be used to write numbers in the system. The value of these symbols range from 0 to N-1 All systems we use in computing are positional systems 495 =

Conversions

Decimal Equivalents Assuming the bits are unsigned, the decimal value represented by the bits of a byte can be calculated as follows: 1. Number the bits beginning on the right using superscripts beginning with 0 and increasing as you move left Note: 2 0, by definition is 1 2. Use each superscript as an exponent of a power of 2 3. Multiply the value of each bit by its corresponding power of 2 4. Add the products obtained

Horner’s Method Another procedure to calculate the decimal equivalent of a binary number Note: This method works with any base Horner’s Method: Step 1: Start with the first digit on the left Step 2: Multiply it by the base Step 3: Add the next digit Step 4: Multiply the sum by the base Step 5: Continue the process until you add the last digit

Binary to Hex Step 1: Form four-bit groups beginning from the rightmost bit of the binary number If the last group (at the leftmost position) has less than four bits, add extra zeros to the left of the group to make it a four-bit group becomes Step 2: Replace each four-bit group by its hexadecimal equivalent 19EAA7 (16

Converting Decimal to Other Bases Step 1: Divide the number by the base you are converting to (r) Step 2: Successively divide the quotients by (r) until a zero quotient is obtained Step 3: The decimal equivalent is obtained by writing the remainders of the successive division in the opposite order in which they were obtained Know as modulus arithmetic Step 4: Verify the result by multiplying it out

Addition & Subtraction Terms A + B A is the augend B is the addend C – D C is the minuend D is the subtrahend

Addition Rules – All Bases Addition Step 1: Add a column of numbers Step 2: Determine if there is a single symbol for the result Step 3: If so, write it and go to the next column. If not, write the accompanying number and carry the appropriate value to the next column

Subtraction Rules – All Bases Step1: Start with the rightmost column, if the column of the minuend is greater than that of the subtrahend, do the subtraction, if not… Step 2: Borrow one unit from the digit to the left of the once being processed The borrowed unit is equal to “borrowing” the radix Step 4: Decrease the column form which you borrowed by one Step 3: Subtract the subtrahend from the minuend and go to the next column

Addition of Binary Numbers Rules for adding or subtracting very similar to the ones in decimal system Limited to only two digits = = = = 0 carry 1

Addition & Subtraction of Hex Due to the propensity for errors in binary, it is preferable to carry out arithmetic in hexadecimal and convert back to binary If we need to borrow in hex, we borrow 16 It is convenient to think “in decimal” and then translate the results back to hex

Representing Signed Numbers Remember, all numeric data is represented inside the computer as 1s and 0s Arithmetic operations, particularly subtraction raise the possibility that the result might be negative Any numerical convention needs to differentiate two basic elements of any given number, its sign and its magnitude Conventions Sign-magnitude Two’s complement One’s complement

Representing Negatives It is necessary to choose one of the bits of the “basic unit” as a sign bit Usually the leftmost bit By convention, 0 is positive and 1 is negative Positive values have the same representation in all conventions However, in order to interpret the content of any memory location correctly, it necessary to know the convention being used used for negative numbers

Comparing the Conventions

Sign-Magnitude For a basic unit of N bits, the leftmost bit is used exclusively to represent the sign The remaining (N-1) bits are used for the magnitude The range of number represented in this convention is –2 N+1 to +2 N-1 -1

Sign-magnitude Operations Addition of two numbers in sign-magnitude is carried out using the usual conventions of binary arithmetic If both numbers are the same sign, we add their magnitude and copy the same sign If different signs, determine which number has the larger magnitude and subtract the other from it. The sign of the result is the sign of the operand with the larger magnitude If the result is outside the bounds of –2 n+1 to +2 n-1 –1, an overflow results

One’s Complement Convention Devised to make the addition of two numbers with different signs the same as two numbers with the same sign Positive numbers are represented in the usual way For negatives STEP 1: Start with the binary representation of the absolute value STEP 2: Complement all of its bits

One's Complement Operations Treat the sign bit as any other bit For addition, carry out of the leftmost bit is added to the rightmost bit – end-around carry

Two’s Complement Convention A positive number is represented using a procedure similar to sign-magnitude To express a negative number 1. Express the absolute value of the number in binary 2. Change all the zeros to ones and all the ones to zeros (called “complementing the bits”) 3. Add one to the number obtained in Step 2 – The range of negative numbers is one larger than the range of positive numbers – Given a negative number, to find its positive counterpart, use steps 2 & 3 above

Two’s Complement Operations Addition: Treat the numbers as unsigned integers The sign bit is treated as any other number Ignore any carry on the leftmost position Subtraction Treat the numbers as unsigned integers If a "borrow" is necessary in the leftmost place, borrow as if there were another “invisible” one-bit to the left of the minuend

Overflows in Two’s Complement The range of values in two’s-complement is –2 n+1 to +2 n-1 –1 Results outside this band are overflows In all overflow conditions, the sign of the result of the operation is different than that of the operands If the operands are positive, the result is negative If the operands are negative, the result is positive

Transmission Errors When binary data is transmitted, there is a possibility of an error in transmission due to equipment failure or "noise" Bits change from 0 to 1 or vice-versa

Categorizing Coding Schemes The number of bits that have to change within a byte before it becomes invalid characterizes the code Single-error-detecting code To detect single errors have occurred we use an added parity check bit – makes each byte either even or odd Two-error-detecting code

Error Detection: Even Parity Bytes Transmitted Parity Block B I T Bytes Received Parity Block B I T