Intro to Computer Systems Recitation #1 By sseshadr.

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Advertisements

15213 Recitation Fall 2014 Section A, 8 th September Vinay Bhat.
When NOT to use Unsigned? Don’t Use Just Because Number Nonzero – C compilers on some machines generate less efficient code unsigned i; for (i = 1; i
Arithmetic & Logic Unit Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point.
Introduction to C Programming CE Lecture 8 Bitwise Operations.
Number Systems Standard positional representation of numbers:
The If/Else Statement, Boolean Flags, and Menus Page 180
February 4, 2003 CSCE 212 Computer Architecture Lecture 3 Representing Integers.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Unsigned and Signed Numbers. Hexadecimal Number 217A 16 Position Digits A Value = 2x x x16 + Ax1 = 2x x x16.
Binary Arithmetic Math For Computers.
Binary numbers and arithmetic. ADDITION Addition (decimal)
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Simple Data Type Representation and conversion of numbers
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
Computer Architecture Lecture 3: Logical circuits, computer arithmetics Piotr Bilski.
Conversion Between Lengths Positive number pack with leading zeros +18 = = Negative numbers pack with leading ones -18 =
1 Homework Turn in HW2 tonight HW3 is on-line already Questions?
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
“The course that gives CMU its Zip!” Topics Basic operations –Addition, negation, multiplication Programming Implications –Consequences of overflow.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
1 Saint Louis University Arithmetic and Bitwise Operations on Binary Data CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides.
15213 Recitation Section C Introduction Unix and C Playing with Bits Practice Problems Shimin Chen Sept. 9, 2002 Outline.
University of Washington Integers The Hardware/Software Interface CSE351 Winter 2013.
CS 105 “Tour of the Black Holes of Computing” Topics Numeric Encodings Unsigned & Two’s complement Programming Implications C promotion rules Basic operations.
Arithmetic Operations
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
1 Carnegie Mellon Welcome to recitation! : Introduction to Computer Systems 3 rd Recitation, Sept. 10, 2012 Instructor: Adrian Trejo (atrejo) Section.
CS 105 “Tour of the Black Holes of Computing” Topics Numeric Encodings Unsigned & Two’s complement Programming Implications C promotion rules Basic operations.
Negative binary numbers 1 Computer Architectures M.
1 COMS 161 Introduction to Computing Title: Computing Basics Date: September 8, 2004 Lecture Number: 7.
“The course that gives CMU its Zip!” Topics Basic operations –Addition, negation, multiplication Programming Implications –Consequences of overflow.
Number Representation and Arithmetic Circuits
Integers Topics Representations of Integers Basic properties and operations Implications for C.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
1 Floating Point. 2 Topics Fractional Binary Numbers IEEE 754 Standard Rounding Mode FP Operations Floating Point in C Suggested Reading: 2.4.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Computer Engineering page 1 Integer arithmetic Depends what you mean by “integer”. Assume at 3-bit string. –Then we define: zero = 000 one = 001 Use zero,
Signed binary numbers & Binary Codes
Addition and Subtraction
Topics IEEE Floating Point Standard Rounding Floating Point Operations
Boolean Algebra, Bitwise Operations
University of Washington
Instructor: David Ferry
Section 2: Integer & Floating Point Numbers
S09 Recitation #1 Jernej Barbic (S06) Revised: Alex Gartrell (S09)
C Puzzles Taken from old exams
Comp Integers Spring 2015 Topics Numeric Encodings
Bits, Bytes, and Integers January 16, 2008
1 The Hardware/Software Interface CSE351 Spring 2011 Module 3: Integers Monday, April 4, 2011.
Homework Homework Continue Reading K&R Chapter 2 Questions?
Computer Organization COMP 210
Computer Organization COMP 210
Presentation transcript:

Intro to Computer Systems Recitation #1 By sseshadr

 Introductions  Datalab Tricks Floating point questions? Go to Office Hours.  Integer Puzzles  Parity Example  Style

 Basics >>, << | vs. || & vs. && ! vs. ~  What is x? int x = (9 | 12) << 1; x = 26

 Trick #1: Signed-ness The MOST significant bit  0 -> positive or zero  1 -> negative What is…  int x = (10 >> 31);  int y = (-10 >> 31);  It’s NOT 1 (what is arithmetic shifting?)  How do we fix that? Answers:  x = 0 and y = -1

 Trick #2: Properties of Zero Masking  0 & (something) == 0 [why?]  (0-1) & (something) == something [why?]  Why is this useful? Positive zero vs. negative zero  int x = 0; int y = -x;  Neither x nor y is negative (MSB is 0 for both)  Why is this useful?

 Trick #3: Negation Review: take a 5-bit twos compliment system = -14

 Trick #3: Negation Review: take a 5-bit twos compliment system = 14

 Trick #3: Negation Example: int x = -14; // int y = ~x; // int z = ~x+1; // 14

 Trick #3: Negation In general -x == (~x + 1) Does this always work?  Tmin?  No!  Tmax?  Yes!  Zero?  Yes!  Everything else?  Yes!

 (x ((x*2) < 0) Nope. Tmin?  (ux >= 0) Yup!  (x&7 == 7) => ((x << 30) < 0) Yup! (x&7 == 7) means last 3 bits are 1 Examine the “negative bit” of (x<<30)

 (ux > -1) Nope. Unsigned comparison means -1 is Tmax!  (x > y) => (-x < -y) Nope. Boundary cases. x = 0, y = Tmin (what is -Tmin?)  (x*x >= 0) Nope. Overflow into “negative bit” int x = 65535; // 2^16 - 1

 (x > 0 && y > 0) => (x + y > 0) Nope. Overflow into “negative bit” x, y = Tmax  (x >= 0) => (-x <= 0) Yup! Why doesn’t break for Tmax?  (x (-x >= 0) Nope. What is –Tmin?

 (x|-x) >> 31 == -1 Nope. x = 0  (ux >> 3) == (ux / 8) Yup!  (x >> 3) == (x / 8) Nope. Careful on rounding! int x = -19; int y = x >> 3;// y = -3 int z = x / 8;// z = -2

 (x & (x-1)) != 0 Nope. x = 0, x = 1

 Write a function which takes an integer and returns 1 if there are an odd number of ‘1’ bits 0 if there are an even number of ‘1’ bits int parity_check(int x){ … }  Any ideas?

 Inspiration: If we could XOR all of the bits in the argument… we would get the answer! XOR (down to 16 bits)

 Just keep going! XOR (down to 8 bits)

 Just keep going! XOR 0101 (down to 4 bits)

 You can take it from there. Still confused on high-level algorithm? Can’t write the C code for the Parity Problem? Office Hours.

 Here is what we grade on:  It is in your best interest to read it ASAP!  Autolab isn’t the whole grade. We read your code.

 Documentation  Whitespace  Line length  Variable names  Magic Numbers  Dead Code  Modularity  Error checking  Consistency