# 9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System

Save this PDF as:

Size: px
Start display at page:

Download "9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System"

## Transcription

1 For Your Amusement Number Systems and Number Representation Jennifer Rexford Question: Why do computer programmers confuse Christmas and Halloween? Answer: Because 25 Dec = 31 Oct Goals of this Lecture Agenda Help you learn (or refresh your memory) about: The binary, hexadecimal, and octal number systems Finite representation of rational numbers (if time) A power programmer must know number systems and data representation to fully understand C s primitive data types Number Systems Finite representation of rational numbers (if time) Primitive values and the operations on them 3 4 The Decimal Number System Name decem (Latin) => ten Characteristics Ten symbols Positional = (2*10 3 ) + (9*10 2 ) + (4*10 1 ) + (5*10 0 ) (Most) people use the decimal number system The Binary Number System Name binarius (Latin) => two Characteristics Two symbols 0 1 Positional 1010 B 1100 B Most (digital) computers use the binary number system Terminology Bit: a binary digit Byte: (typically) 8 bits 5 6 1

2 Decimal-Binary Equivalence Decimal-Binary Conversion Decimal Binary Decimal Binary Binary to decimal: expand using positional notation B = (1*2 5 )+(0*2 4 )+(0*2 3 )+(1*2 2 )+(0*2 1 )+(1*2 0 ) = = Decimal-Binary Conversion Decimal to binary: do the reverse Determine largest power of 2 number;; write template 37 = (?*2 5 )+(?*2 4 )+(?*2 3 )+(?*2 2 )+(?*2 1 )+(?*2 0 ) Fill in template 37 = (1*2 5 )+(0*2 4 )+(0*2 3 )+(1*2 2 )+(0*2 1 )+(1*2 0 ) B -1 0 Decimal-Binary Conversion Decimal to binary shortcut Repeatedly divide by 2, consider remainder 37 / 2 = 18 R 1 18 / 2 = 9 R 0 9 / 2 = 4 R 1 4 / 2 = 2 R 0 2 / 2 = 1 R 0 1 / 2 = 0 R 1 Read from bottom to top: B 9 10 The Hexadecimal Number System Decimal-Hexadecimal Equivalence Name hexa (Greek) => six decem (Latin) => ten Characteristics Sixteen symbols A B C D E F Positional A13D H 3DA1 H Computer programmers often use the hexadecimal number system Decimal Hex A 11 B 12 C 13 D 14 E 15 F Decimal Hex A 27 1B 28 1C 29 1D 30 1E 31 1F Decimal Hex A 43 2B 44 2C 45 2D 46 2E 47 2F

4 Agenda Number Systems Finite representation of rational numbers (if time) Unsigned Data Types: Java vs. C Java has type: int Can represent signed integers C has type: signed int Can represent signed integers int Same as signed int unsigned int Can represent only unsigned integers To understand C, must consider representation of both unsigned and signed integers Representing Unsigned Integers Representing Unsigned Integers Mathematics Range is 0 to Computer programming Range limited by computer s word size Word size is n bits => range is 0 to 2 n 1 Exceed range => overflow FC010 computers n = 64, so range is 0 to (huge!) Pretend computer n = 4, so range is 0 to (15) Hereafter, assume word size = 4 All points generalize to word size = 64, word size = n 21 On pretend computer Unsigned Adding Unsigned Integers Subtracting Unsigned Integers Addition Subtraction B B 11 B B B Results are mod 2 4 Start at right column Proceed leftward Carry 1 when necessary Beware of overflow How would you detect overflow programmatically? B B B B Results are mod 2 4 Start at right column Proceed leftward Borrow 2 when necessary Beware of overflow How would you detect overflow programmatically?

5 Shifting Unsigned Integers Bitwise right shift (>> in C): fill on left with zeros 10 >> 1 => B 0101B 10 >> 2 => B 0010B arithmetically? (No fair looking ahead) Bitwise left shift (<< in C): fill on right with zeros Other Operations on Unsigned Ints Bitwise NOT (~ in C) Flip each bit ~10 => B 0101B Bitwise AND (& in C) Logical AND corresponding bits 5 << 1 => B 1010B 3 << 2 => B 1100B Results are mod 2 4 arithmetically? (No fair looking ahead) B & 7 & 0111B B Useful for setting selected bits to Other Operations on Unsigned Ints Bitwise OR: ( in C) Logical OR corresponding bits B B B Useful for setting selected bits to 1 Bitwise exclusive OR (^ in C) Logical exclusive OR corresponding bits B ^ 10 ^ 1010B B x ^ x sets all bits to 0 Aside: Using Bitwise Ops for Arith Can use <<, >>, and & to do some arithmetic efficiently x * 2 y == x << y 3*4 = 3*2 2 = 3<<2 => 12 x / 2 y == x >> y 13/4 = 13/2 2 = 13>>2 => 3 x % 2 y == x & (2 y -1) 13%4 = 13%2 2 = 13&(2 2-1) = 13&3 => B & 3 & 0011B B Fast way to multiply by a power of 2 Fast way to divide by a power of 2 Fast way to mod by a power of Aside: Example C Program Agenda #include <stdio.h> #include <stdlib.h> int main(void) { unsigned int n; unsigned int count; printf("enter an unsigned integer: "); if (scanf("%u", &n)!= 1) { fprintf(stderr, "Error: Expect unsigned int.\n"); exit(exit_failure); } for (count = 0; n > 0; n = n >> 1) count += (n & 1); printf("%u\n", count); return 0; } What does it write? How could this be expressed more succinctly? Number Systems Finite representation of rational numbers (if time)

6 Signed Magnitude Signed Magnitude (cont.) Definition High-order bit indicates sign 0 => positive 1 => negative Remaining bits indicate magnitude 1101 B = -101 B = B = 101 B = Computing negative neg(x) = flip high order bit of x neg(0101 B ) = 1101 B neg(1101 B ) = 0101 B Pros and cons + easy for people to understand + symmetric - two reps of zero Ones Complement Ones Complement (cont.) Definition High-order bit has weight B = (1*-7)+(0*4)+(1*2)+(0*1) = B = (0*-7)+(0*4)+(1*2)+(0*1) = Computing negative neg(x) = ~x neg(0101 B ) = 1010 B neg(1010 B ) = 0101 B Computing negative (alternative) neg(x) = 1111 B - x neg(0101 B ) = 1111 B 0101 B = 1010 B neg(1010 B ) = 1111 B 1010 B = 0101 B Pros and cons + symmetric - two reps of zero 34 Two s Complement Two s Complement (cont.) Definition High-order bit has weight B = (1*-8)+(0*4)+( 1*2 )+ (0* 1) = B = (0*-8)+(0*4)+( 1*2 )+ (0* 1) = Computing negative neg(x) = ~x + 1 neg(x) = onescomp(x) + 1 neg(0101 B ) = 1010 B + 1 = 1011 B neg(1011 B ) = 0100 B + 1 = 0101 B Pros and cons - not symmetric + one rep of zero 36 6

7 Two s Complement (cont.) Adding Signed Integers Almost all computers use two s complement to represent signed integers Arithmetic is easy Will become clear soon Hereafter, assume two s complement representation of signed integers pos + pos B B pos + neg B B pos + pos (overflow) 111 B B B How would you detect overflow programmatically? 37 neg + neg B B B neg + neg (overflow) B B B 38 Subtracting Signed Integers Negating Signed Ints: Math Perform subtraction with borrows or Compute two s comp and add Question: Why does two s comp arithmetic work? Answer: [ b] mod 2 4 = [twoscomp(b)] mod B B B B B B B [ b] mod 2 4 = [2 4 b] mod 2 4 = [ b + 1] mod 2 4 = [( b) + 1] mod 2 4 = [onescomp(b) + 1] mod 2 4 = [twoscomp(b)] mod 2 4 See Bryant & O Hallaron book for much more info Subtracting Signed Ints: Math Shifting Signed Integers Bitwise left shift (<< in C): fill on right with zeros And so: [a b] mod 2 4 = [a + twoscomp(b)] mod 2 4 [a b] mod 2 4 = [a b] mod 2 4 = [a b + 1] mod 2 4 = [a + (2 4-1 b) + 1] mod 2 4 = [a + onescomp(b) + 1] mod 2 4 = [a + twoscomp(b)] mod 2 4 See Bryant & O Hallaron book for much more info 41 3 << 1 => B 0110B -3 << 1 => B -1010B Bitwise arithmetic right shift: fill on left with sign bit 6 >> 1 => B 0011B -6 >> 1 => B 1101B Results are mod 2 4 arithmetically? arithmetically? 42 7

8 Shifting Signed Integers (cont.) Bitwise logical right shift: fill on left with zeros 6 >> 1 => B -6 >> 1 => B 0011B 0101B In C, right shift (>>) could be logical or arithmetic Not specified by C90 standard Compiler designer decides Best to avoid shifting signed integers arithmetically??? Other Operations on Signed Ints Bitwise NOT (~ in C) Same as with unsigned ints Bitwise AND (& in C) Same as with unsigned ints Bitwise OR: ( in C) Same as with unsigned ints Bitwise exclusive OR (^ in C) Same as with unsigned ints Best to avoid with signed integers Agenda Rational Numbers Number Systems Finite representation of rational numbers (if time) Mathematics A rational number is one that can be expressed as the ratio of two integers Infinite range and precision Computer science Finite range and precision Approximate using floating point number Binary point floats across bits IEEE Floating Point Representation Common finite representation: IEEE floating point More precisely: ISO/IEEE 754 standard Using 32 bits (type float in C): 1 bit: sign (0=>positive, 1=>negative) 8 bits: exponent bits: binary fraction of the form 1.ddddddddddddd dd ddd dd ddd Using 64 bits (type double in C): 1 bit: sign (0=>positive, 1=>negative) 11 bits: exponent bits: binary fraction of the form 1.ddddddddddddd ddd dd ddd dd ddd dd ddd dd ddd dd ddd dd ddd dd ddd d Floating Point Example Sign (1 bit): 1 => negative Exponent (8 bits): B = = 4 Fraction (23 bits): B 1 + (1*2-1 )+(0*2-2 )+(1*2-3 )+(1*2-4 )+(0*2-5 )+(1*2-6 )+(1*2-7 ) = Number: * 2 4 = bit representation

9 Floating Point Warning Decimal number system can represent only some rational numbers with finite digit count Example: 1/3 Binary number system can represent only some rational numbers with finite digit count Example: 1/5 Beware of roundoff error Error resulting from inexact representation Can accumulate Decimal Rational Approx Value.3 3/ / / Binary Rational Approx Value 0.0 0/ / / / / / / / Summary The binary, hexadecimal, and octal number systems Finite representation of rational numbers Essential for proper understanding of C primitive data types Assembly language Machine language

### A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Complement Number Systems A complement number system is used to represent positive and negative integers A complement number system is based on a fixed length representation of numbers Pretend that integers

Octal and Hexadecimal Integers CS 350: Computer Organization & Assembler Language Programming A. Why? Octal and hexadecimal numbers are useful for abbreviating long bitstrings. Some operations on octal

### 1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

CS 64 Lecture 2 Data Representation Reading: FLD 1.2-1.4 Decimal Numbers: Base 10 Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Example: 3271 = (3x10 3 ) + (2x10 2 ) + (7x10 1 ) + (1x10 0 ) 1010 10?= 1010 2?= 1

### 10.1. Unit 10. Signed Representation Systems Binary Arithmetic

0. Unit 0 Signed Representation Systems Binary Arithmetic 0.2 BINARY REPRESENTATION SYSTEMS REVIEW 0.3 Interpreting Binary Strings Given a string of s and 0 s, you need to know the representation system

### IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

IT 1204 Section 2.0 Data Representation and Arithmetic 2009, University of Colombo School of Computing 1 What is Analog and Digital The interpretation of an analog signal would correspond to a signal whose

### Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations How do we represent data in a computer? At the lowest level, a computer is an electronic machine. works by controlling the flow of electrons Easy to recognize

### Signed Binary Numbers

Signed Binary Numbers Unsigned Binary Numbers We write numbers with as many digits as we need: 0, 99, 65536, 15000, 1979, However, memory locations and CPU registers always hold a constant, fixed number

### Inf2C - Computer Systems Lecture 2 Data Representation

Inf2C - Computer Systems Lecture 2 Data Representation Boris Grot School of Informatics University of Edinburgh Last lecture Moore s law Types of computer systems Computer components Computer system stack

### Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Appendix F Number Systems Binary Numbers Decimal notation represents numbers as powers of 10, for example 1729 1 103 7 102 2 101 9 100 decimal = + + + There is no particular reason for the choice of 10,

### Fundamentals of Programming Session 2

Fundamentals of Programming Session 2 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 Sharif University of Technology Outlines Programming Language Binary numbers Addition Subtraction

### CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

CS 265 Computer Architecture Wei Lu, Ph.D., P.Eng. 1 Part 1: Data Representation Our goal: revisit and re-establish fundamental of mathematics for the computer architecture course Overview: what are bits

### Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

Course Schedule CS 221 Computer Architecture Week 3: Information Representation (2) Fall 2001 W1 Sep 11- Sep 14 Introduction W2 Sep 18- Sep 21 Information Representation (1) (Chapter 3) W3 Sep 25- Sep

### EE 109 Unit 6 Binary Arithmetic

EE 109 Unit 6 Binary Arithmetic 1 2 Semester Transition Point At this point we are going to start to transition in our class to look more at the hardware organization and the low-level software that is

### Chapter 2: Number Systems

Chapter 2: Number Systems Logic circuits are used to generate and transmit 1s and 0s to compute and convey information. This two-valued number system is called binary. As presented earlier, there are many

### DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

Data Representation Data Representation Goal: Store numbers, characters, sets, database records in the computer. What we got: Circuit that stores 2 voltages, one for logic 0 (0 volts) and one for logic

### Module 2: Computer Arithmetic

Module 2: Computer Arithmetic 1 B O O K : C O M P U T E R O R G A N I Z A T I O N A N D D E S I G N, 3 E D, D A V I D L. P A T T E R S O N A N D J O H N L. H A N N E S S Y, M O R G A N K A U F M A N N

### Arithmetic and Bitwise Operations on Binary Data

Arithmetic and Bitwise Operations on Binary Data CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant & O Hallaron s slides 1 Boolean Algebra Developed by

### l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

198:211 Computer Architecture Topics: Lecture 8 (W5) Fall 2012 Data representation 2.1 and 2.2 of the book Floating point 2.4 of the book Computer Architecture What do computers do? Manipulate stored information

### 1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM 1.1 Introduction Given that digital logic and memory devices are based on two electrical states (on and off), it is natural to use a number

### COMP 122/L Lecture 2. Kyle Dewey

COMP 122/L Lecture 2 Kyle Dewey Outline Operations on binary values AND, OR, XOR, NOT Bit shifting (left, two forms of right) Addition Subtraction Twos complement Bitwise Operations Bitwise AND Similar

### Binary Addition & Subtraction. Unsigned and Sign & Magnitude numbers

Binary Addition & Subtraction Unsigned and Sign & Magnitude numbers Addition and subtraction of unsigned or sign & magnitude binary numbers by hand proceeds exactly as with decimal numbers. (In fact this

### Signed umbers. Sign/Magnitude otation

Signed umbers So far we have discussed unsigned number representations. In particular, we have looked at the binary number system and shorthand methods in representing binary codes. With m binary digits,

### Data Representation. DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

Data Representation Data Representation Goal: Store numbers, characters, sets, database records in the computer. What we got: Circuit that stores 2 voltages, one for logic ( volts) and one for logic (3.3

### Logic, Words, and Integers

Computer Science 52 Logic, Words, and Integers 1 Words and Data The basic unit of information in a computer is the bit; it is simply a quantity that takes one of two values, 0 or 1. A sequence of k bits

### 4/8/17. Admin. Assignment 5 BINARY. David Kauchak CS 52 Spring 2017

4/8/17 Admin! Assignment 5 BINARY David Kauchak CS 52 Spring 2017 Diving into your computer Normal computer user 1 After intro CS After 5 weeks of cs52 What now One last note on CS52 memory address binary

### System Programming CISC 360. Floating Point September 16, 2008

System Programming CISC 360 Floating Point September 16, 2008 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Powerpoint Lecture Notes for Computer Systems:

### Section 1.4 Mathematics on the Computer: Floating Point Arithmetic

Section 1.4 Mathematics on the Computer: Floating Point Arithmetic Key terms Floating point arithmetic IEE Standard Mantissa Exponent Roundoff error Pitfalls of floating point arithmetic Structuring computations

### Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

1 Floating Point The World is Not Just Integers Programming languages support numbers with fraction Called floating-point numbers Examples: 3.14159265 (π) 2.71828 (e) 0.000000001 or 1.0 10 9 (seconds in

### Data Representation Floating Point

Data Representation Floating Point CSCI 2400 / ECE 3217: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides via Jason Fritts Today: Floating Point Background:

### CHAPTER 2 Data Representation in Computer Systems

CHAPTER 2 Data Representation in Computer Systems 2.1 Introduction 37 2.2 Positional Numbering Systems 38 2.3 Decimal to Binary Conversions 38 2.3.1 Converting Unsigned Whole Numbers 39 2.3.2 Converting

### CHAPTER 2 Data Representation in Computer Systems

CHAPTER 2 Data Representation in Computer Systems 2.1 Introduction 37 2.2 Positional Numbering Systems 38 2.3 Decimal to Binary Conversions 38 2.3.1 Converting Unsigned Whole Numbers 39 2.3.2 Converting

### Octal & Hexadecimal Number Systems. Digital Electronics

Octal & Hexadecimal Number Systems Digital Electronics What, More Number Systems? Why do we need more number systems? Humans understand decimal Check out my ten digits! Digital electronics (computers)

### Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

Digital Arithmetic Digital Arithmetic: Operations and Circuits Dr. Farahmand Binary Arithmetic Digital circuits are frequently used for arithmetic operations Fundamental arithmetic operations on binary

### 4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.

### CS321. Introduction to Numerical Methods

CS31 Introduction to Numerical Methods Lecture 1 Number Representations and Errors Professor Jun Zhang Department of Computer Science University of Kentucky Lexington, KY 40506 0633 August 5, 017 Number

### Digital Computers and Machine Representation of Data

Digital Computers and Machine Representation of Data K. Cooper 1 1 Department of Mathematics Washington State University 2013 Computers Machine computation requires a few ingredients: 1 A means of representing

### 3.5 Floating Point: Overview

3.5 Floating Point: Overview Floating point (FP) numbers Scientific notation Decimal scientific notation Binary scientific notation IEEE 754 FP Standard Floating point representation inside a computer

### 4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.

### But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

Integer Representation Representation of integers: unsigned and signed Sign extension Arithmetic and shifting Casting But first, encode deck of cards. cards in suits How do we encode suits, face cards?

### Numbers and Representations

Çetin Kaya Koç http://koclab.cs.ucsb.edu/teaching/cs192 koc@cs.ucsb.edu Çetin Kaya Koç http://koclab.cs.ucsb.edu Fall 2016 1 / 38 Outline Computational Thinking Representations of integers Binary and decimal

### ECE 372 Microcontroller Design Assembly Programming Arrays. ECE 372 Microcontroller Design Assembly Programming Arrays

Assembly Programming Arrays Assembly Programming Arrays Array For Loop Example: unsigned short a[]; for(j=; j

### C NUMERIC FORMATS. Overview. IEEE Single-Precision Floating-point Data Format. Figure C-0. Table C-0. Listing C-0.

C NUMERIC FORMATS Figure C-. Table C-. Listing C-. Overview The DSP supports the 32-bit single-precision floating-point data format defined in the IEEE Standard 754/854. In addition, the DSP supports an

### Number Systems Using and Converting Between Decimal, Binary, Octal and Hexadecimal Number Systems

Number Systems Using and Converting Between Decimal, Binary, Octal and Hexadecimal Number Systems In everyday life, we humans most often count using decimal or base-10 numbers. In computer science, it

### Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

Systems I Floating Point Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties IEEE Floating Point IEEE Standard 754 Established in 1985 as uniform standard for

### Bits, Bytes and Integers

Bits, Bytes and Integers Computer Systems Organization (Spring 2016) CSCI-UA 201, Section 2 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed Zahran

### ENE 334 Microprocessors

Page 1 ENE 334 Microprocessors Lecture 10: MCS-51: Logical and Arithmetic : Dejwoot KHAWPARISUTH http://webstaff.kmutt.ac.th/~dejwoot.kha/ ENE 334 MCS-51 Logical & Arithmetic Page 2 Logical: Objectives

### Appendix. Numbering Systems. In this Appendix

Numbering Systems ppendix n this ppendix ntroduction... inary Numbering System... exadecimal Numbering System... Octal Numbering System... inary oded ecimal () Numbering System... 5 Real (Floating Point)

### Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Floating point Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties Next time! The machine model Chris Riesbeck, Fall 2011 Checkpoint IEEE Floating point Floating

### Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

Chapter 2 Float Point Arithmetic Topics IEEE Floating Point Standard Fractional Binary Numbers Rounding Floating Point Operations Mathematical properties Real Numbers in Decimal Notation Representation

### CS101 Lecture 04: Binary Arithmetic

CS101 Lecture 04: Binary Arithmetic Binary Number Addition Two s complement encoding Briefly: real number representation Aaron Stevens (azs@bu.edu) 25 January 2013 What You ll Learn Today Counting in binary

### ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

### Characters, Strings, and Floats

Characters, Strings, and Floats CS 350: Computer Organization & Assembler Language Programming 9/6: pp.8,9; 9/28: Activity Q.6 A. Why? We need to represent textual characters in addition to numbers. Floating-point

### Floating point. Today. IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.

Floating point Today IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time The machine model Fabián E. Bustamante, Spring 2010 IEEE Floating point Floating point

### Computer Systems Programming. Practice Midterm. Name:

Computer Systems Programming Practice Midterm Name: 1. (4 pts) (K&R Ch 1-4) What is the output of the following C code? main() { int i = 6; int j = -35; printf( %d %d\n,i++, ++j); i = i >

### Chapter 2 Binary Values and Number Systems

Chapter 2 Binary Values and Number Systems Chapter Goals 10 進位 2 / 8 / 16 進位 進位系統間轉換 各進位系統小數表示 各進位系統加減法 各進位系統乘除法 2 24 6 Numbers Natural Numbers Zero and any number obtained by repeatedly adding one to

### Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

Points ddressed in this Lecture Lecture 6: Signed Numbers rithmetic Circuits Professor Peter Cheung Department of EEE, Imperial College London (Floyd 2.5-2.7, 6.1-6.7) (Tocci 6.1-6.11, 9.1-9.2, 9.4) Representing

### Bits, Bytes, and Integers Part 2

Bits, Bytes, and Integers Part 2 15-213: Introduction to Computer Systems 3 rd Lecture, Jan. 23, 2018 Instructors: Franz Franchetti, Seth Copen Goldstein, Brian Railing 1 First Assignment: Data Lab Due:

### CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: September 18, 2017 at 12:48 CS429 Slideset 4: 1 Topics of this Slideset

### ICS Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2

ICS 2008 Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2 Data Representations Sizes of C Objects (in Bytes) C Data Type Compaq Alpha Typical 32-bit Intel IA32 int 4 4 4 long int 8 4 4

### CSC201, SECTION 002, Fall 2000: Homework Assignment #2

1 of 7 11/8/2003 7:34 PM CSC201, SECTION 002, Fall 2000: Homework Assignment #2 DUE DATE Monday, October 2, at the start of class. INSTRUCTIONS FOR PREPARATION Neat, in order, answers easy to find. Staple

### Number Systems & Encoding

Number Systems & Encoding Lecturer: Sri Parameswaran Author: Hui Annie Guo Modified: Sri Parameswaran Week2 1 Lecture overview Basics of computing with digital systems Binary numbers Floating point numbers

### CSCI 2212: Intermediate Programming / C Chapter 15

... /34 CSCI 222: Intermediate Programming / C Chapter 5 Alice E. Fischer October 9 and 2, 25 ... 2/34 Outline Integer Representations Binary Integers Integer Types Bit Operations Applying Bit Operations

### LAB A Translating Data to Binary

LAB A Translating Data to Binary Create a directory for this lab and perform in it the following groups of tasks: LabA1.java 1. Write the Java app LabA1 that takes an int via a command-line argument args[0]

### Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.

class04.ppt 15-213 The course that gives CMU its Zip! Topics Floating Point Jan 22, 2004 IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Floating Point Puzzles For

### Number Systems and Computer Arithmetic

Number Systems and Computer Arithmetic Counting to four billion two fingers at a time What do all those bits mean now? bits (011011011100010...01) instruction R-format I-format... integer data number text

### ECE2049 E17 Lecture 2: Data Representations & C Programming Basics

ECE2049 E17 Lecture 2: Data Representations & C Programming Basics Administrivia Lab 0 after class today! o Get your MSP430 board! Install instructions for CCS are on course website under Resources o You

### IBM 370 Basic Data Types

IBM 370 Basic Data Types This lecture discusses the basic data types used on the IBM 370, 1. Two s complement binary numbers 2. EBCDIC (Extended Binary Coded Decimal Interchange Code) 3. Zoned Decimal

### Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Carnegie Mellon 1 Bits, Bytes and Integers Part 1 15-213/18-213/15-513: Introduction to Computer Systems 2 nd Lecture, Aug. 31, 2017 Today s Instructor: Randy Bryant 2 Announcements Recitations are on

### Computer Architecture and Organization

3-1 Chapter 3 - Arithmetic Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 3 Arithmetic 3-2 Chapter 3 - Arithmetic Chapter Contents 3.1 Fixed Point Addition and Subtraction

### CS/EE1012 INTRODUCTION TO COMPUTER ENGINEERING SPRING 2013 HOMEWORK I. Solve all homework and exam problems as shown in class and sample solutions

CS/EE2 INTRODUCTION TO COMPUTER ENGINEERING SPRING 23 DUE : February 22, 23 HOMEWORK I READ : Related portions of the following chapters : È Chapter È Chapter 2 È Appendix E ASSIGNMENT : There are eight

### PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 TYPES TYPES Programs have to store and process different kinds of data, such as integers and floating-point numbers, in different ways. To this end, the compiler needs to

### Internal Data Representation

Introduction to Computer Science, Shimon Schocken, IDC Herzliya Lecture 7. Internal Data Representation Internal Data Representation, Shimon Schocken, IDC Herzliya, www.introcs.com slide 1 Why binary representation

### Digital Fundamentals

Digital Fundamentals Tenth Edition Floyd Chapter 1 Modified by Yuttapong Jiraraksopakun Floyd, Digital Fundamentals, 10 th 2008 Pearson Education ENE, KMUTT ed 2009 Analog Quantities Most natural quantities

### UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS (09 periods) Computer Arithmetic: Data Representation, Fixed Point Representation, Floating Point Representation, Addition and

### FLOATING POINT NUMBERS

FLOATING POINT NUMBERS Robert P. Webber, Longwood University We have seen how decimal fractions can be converted to binary. For instance, we can write 6.25 10 as 4 + 2 + ¼ = 2 2 + 2 1 + 2-2 = 1*2 2 + 1*2

### Floating Point Arithmetic

Floating Point Arithmetic CS 365 Floating-Point What can be represented in N bits? Unsigned 0 to 2 N 2s Complement -2 N-1 to 2 N-1-1 But, what about? very large numbers? 9,349,398,989,787,762,244,859,087,678

### Lecture 5: Arithmetic and Algebra Steven Skiena. skiena

Lecture 5: Arithmetic and Algebra Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena How Long is Long? Today s PCs are

### P( Hit 2nd ) = P( Hit 2nd Miss 1st )P( Miss 1st ) = (1/15)(15/16) = 1/16. P( Hit 3rd ) = (1/14) * P( Miss 2nd and 1st ) = (1/14)(14/15)(15/16) = 1/16

CODING and INFORMATION We need encodings for data. How many questions must be asked to be certain where the ball is. (cases: avg, worst, best) P( Hit 1st ) = 1/16 P( Hit 2nd ) = P( Hit 2nd Miss 1st )P(

### Number System (Different Ways To Say How Many) Fall 2016

Number System (Different Ways To Say How Many) Fall 2016 Introduction to Information and Communication Technologies CSD 102 Email: mehwish.fatima@ciitlahore.edu.pk Website: https://sites.google.com/a/ciitlahore.edu.pk/ict/

### MIPS Assembly Programming

COMP 212 Computer Organization & Architecture COMP 212 Fall 2008 Lecture 8 Cache & Disk System Review MIPS Assembly Programming Comp 212 Computer Org & Arch 1 Z. Li, 2008 Comp 212 Computer Org & Arch 2

### Fundamentals of Programming

Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

### CS/COE 0447 Example Problems for Exam 2 Spring 2011

CS/COE 0447 Example Problems for Exam 2 Spring 2011 1) Show the steps to multiply the 4-bit numbers 3 and 5 with the fast shift-add multipler. Use the table below. List the multiplicand (M) and product

### Learning the Binary System

Learning the Binary System www.brainlubeonline.com/counting_on_binary/ Formated to L A TEX: /25/22 Abstract This is a document on the base-2 abstract numerical system, or Binary system. This is a VERY

### Arithmetic Operations

Arithmetic Operations Arithmetic Operations addition subtraction multiplication division Each of these operations on the integer representations: unsigned two's complement 1 Addition One bit of binary

### Name: CMSC 313 Fall 2001 Computer Organization & Assembly Language Programming Exam 1. Question Points I. /34 II. /30 III.

CMSC 313 Fall 2001 Computer Organization & Assembly Language Programming Exam 1 Name: Question Points I. /34 II. /30 III. /36 TOTAL: /100 Instructions: 1. This is a closed-book, closed-notes exam. 2. You

### 2. Integers. 9 * celsius / Celsius to Fahrenheit. Precedence. (9 * celsius / 5) + 32

2. Integers Evaluation of Arithmetic Expressions, Associativity and Precedence, Arithmetic Operators, Domain of Types int, unsigned int 93 Celsius to Fahrenheit // Program: fahrenheit.cpp // Convert temperatures

### CS 253. January 14, 2017

CS 253 Department of Computer Science College of Engineering Boise State University January 14, 2017 1/30 Motivation Most programming tasks can be implemented using abstractions (e.g. representing data

### Scientific Computing. Error Analysis

ECE257 Numerical Methods and Scientific Computing Error Analysis Today s s class: Introduction to error analysis Approximations Round-Off Errors Introduction Error is the difference between the exact solution

### Declaring Floating Point Data

Declaring Floating Point Data There are three ways to declare floating point storage. These are E D L Single precision floating point, Double precision floating point, and Extended precision floating point.

### Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

### CO Computer Architecture and Programming Languages CAPL. Lecture 9

CO20-320241 Computer Architecture and Programming Languages CAPL Lecture 9 Dr. Kinga Lipskoch Fall 2017 A Four-bit Number Circle CAPL Fall 2017 2 / 38 Functional Parts of an ALU CAPL Fall 2017 3 / 38 Addition

### More Programming Constructs -- Introduction

More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

### CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON Prof. Gurindar Sohi, Kai Zhao TAs: Annie Lin, Mohit Verma, Neha Mittal, Daniel Griffin, Yuzhe Ma Examination 1 In Class

### Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

3.1 3.2 Unit 3 Binary Representation ANALOG VS. DIGITAL 3.3 3.4 Analog vs. Digital The analog world is based on continuous events. Observations can take on (real) any value. The digital world is based

### Arithmetic Operations on Binary Numbers

Arithmetic Operations on Binary Numbers Because of its widespread use, we will concentrate on addition and subtraction for Two's Complement representation. The nice feature with Two's Complement is that

### 1.2 Round-off Errors and Computer Arithmetic

1.2 Round-off Errors and Computer Arithmetic 1 In a computer model, a memory storage unit word is used to store a number. A word has only a finite number of bits. These facts imply: 1. Only a small set

### Principles of Computer Architecture. Chapter 3: Arithmetic

3-1 Chapter 3 - Arithmetic Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 3: Arithmetic 3-2 Chapter 3 - Arithmetic 3.1 Overview Chapter Contents 3.2 Fixed Point Addition

### Administrivia. CMSC 216 Introduction to Computer Systems Lecture 24 Data Representation and Libraries. Representing characters DATA REPRESENTATION

Administrivia CMSC 216 Introduction to Computer Systems Lecture 24 Data Representation and Libraries Jan Plane & Alan Sussman {jplane, als}@cs.umd.edu Project 6 due next Friday, 12/10 public tests posted