Integer Encoding and Manipulation

Size: px
Start display at page:

Download "Integer Encoding and Manipulation"

Transcription

1 CSE 2421: Systems I Low-Level Programming and Computer Organization Integer Encoding and Manipulation Presentation D Study: Bryant Chapter Gojko Babić Unsigned & Signed Integer Encoding Let binary number X have w-bit pattern: x w-1 x w-2 x w-3 x 3 x 2 x 1 x 0 x i = 0 or 1 Binary to Unsigned Binary to Two s Complement interpretation interpretation B2T(X) x w 1 2 w 1 w 2 w 1 B2U(X) x x i 2 i i 2 i i 0 For 2 s complement, most significant bit indicates sign 0 for nonnegative 1 for negative i 0 Sign Bit short int x = 15213; short int y = ; or short int x = 0x3B6D; short int y = 0xC493; Decimal Hex Binary x B 6D y C Presentation D 2 1

2 2 s Complement Encoding Examples x = 15213: y = : Weight Sum Unsigned Binary Decimal Conversion from binary unsigned integer to decimal integer = since: = = Conversion from integer to 16-bit binary integer: 927/2 = LSB 463/2 = /2 = /2 = /2 = /2 = /2 = /2 = /2 = /2 = as short int = What about negative integers? g. babic Presentation D 4 2

3 Claim: Following holds for 2 s complement integers: ~x + 1 = x ~x is 1 s complement of x change 1 s to 0 s and 0 s to 1 s Proof: Negation = Complement + Increment ~x + x = = ~x + x = 1 ~x + x +1 x = 1 +1 x ~x +1 = x Example: x = = x = ~x + 1 = = Works from positive 2 s complement integer to negative 2 s complement integer, as well as wise verse. Example: x=0 -x=? + x ~x g. babic Presentation D 5 Numeric Ranges of W-bit Integers Unsigned Values UMin = 0 bit pattern: UMax = 2 w 1 bit pattern: Two s Complement Values TMin = 2 w 1 bit pattern: TMax = 2 w 1 1 bit pattern: Values for W = 16 Decimal Hex Binary UMax FF FF TMax F FF TMin FF FF Presentation D 6 3

4 Values for Different Word Sizes W UMax ,535 4,294,967,295 18,446,744,073,709,551,615 TMax ,767 2,147,483,647 9,223,372,036,854,775,807 TMin ,768 2,147,483,648 9,223,372,036,854,775,808 Observations: TMin = TMax + 1 UMax = 2 * Tmax +1 Integer sizes are platform specific Our C language platform supports: (unsigned) char 1 byte (unsigned) short int 2 bytes (unsigned) int 4 bytes (unsigned) long long int 8 bytes Presentation D 7 4-bit Unsigned & Signed Numeric Values X B2U(X) B2T(X) Equivalence Same encodings for nonnegative values Uniqueness Every bit pattern represents unique integer value Each representable integer has unique bit encoding Presentation D 8 4

5 4-bit Signed Unsigned Mapping Bits Signed Unsigned = / Relation Between Signed & Unsigned Mappings between unsigned and two s complement numbers: keep bit representations, but reinterpret and can have unexpected effect of adding or subtracting 2 w ux w x Largest negative weight becomes large positive weight Presentation D 10 5

6 Signed & Unsigned Conversion Visualized UMax UMax 1 TMax TMax + 1 TMax Unsigned Range 2 s Complement Range TMin Presentation D 11 Unsigned vs. Signed in C By default, decimal constants are considered to be signed integers. Unsigned if have U as suffix: 0U, U Explicit casting between signed & unsigned for same size integers doesn t change bit pattern: int tx, ty; unsigned int ux, uy; tx = (int) ux; uy = (unsigned) ty; Implicit casting also occurs via assignments and function calls: tx = ux; uy = ty; Explicit and implicit casting above gives the same results. Presentation D 12 6

7 Casting Surprises Expression evaluation: If there is a mix of unsigned and signed in single expression, signed values implicitly cast to unsigned; includes arithmetic and relational expressions Examples for W = 32, i.e. 32-bit integers Constant 1 Constant 2 Relation Evaluation 0 0U == unsigned -1 0 < signed -1 0U > unsigned > signed U < unsigned -1-2 > signed (unsigned) -1-2 > unsigned U < unsigned (int) U > signed TMin=-2,147,483,648, TMax=2,147,483,647, UMax=4,294,967,295 Presentation D 13 Expanding & Truncating Integers Expanding refers to converting shorter-bit integer into longer-bit integer, e.g. short int into int Unsigned integers: zeros added Signed integers: sign extension Interesting case: when a shorter signed variable is assigned to a longer unsigned variable E.g.: unsigned int x; short int y; x = y; y is first sign extended to 32-bits, then that value is assigned to x Truncating refers to converting longer-bit integer into shorter-bit integer, e.g., unsigned into unsigned short Unsigned & signed integers: bits are truncated and results are reinterpreted For unsigned integers could be thought as mod operation Presentation D 14 7

8 Task: Given w-bit signed integer X convert it to w+k-bit integer X with same value. Rule: Make k copies of sign bit: X = x w 1,, x w 1, x w 1, x w 2,, x 0 k copies of X W 1 Sign Extension X w X k w Presentation D 15 Sign Extension Examples C automatically performs sign extension when converting from smaller to larger integer data type short int x = 15213; int ix = (int) x; //explicit casting not needed short int y = ; int iy = (int) y; //explicit casting not needed Decimal Hex Binary x B 6D ix B 6D y C iy FF FF C g. babic Presentation D 16 8

9 Mixing Integer Types: Example 1 int main() /*Expanding.c*/ %X an integer argument is { printed in hex; %hx a short int argument is short int si1=0x85ff; printed in hex; unsigned short su1=0x85ff; Output: int i1; su1= 85FF i1= FF unsigned int u1; si1= 85FF u1= FFFF85FF i1=su1; u1=si1; printf("su1= %hx i1= %.8X", su1, i1); printf("\nsi1= %hx u1= %.8X", si1, u1); } g. babic Presentation D 17 Mixing Integer Types: Example 2 int main() { int i1 = 70000, i2; short si1 = -70, si2, si3; si2=i1/si1; si3= (short)i1/si1; i2= (short)(i1/si1); printf("i1%%d= %d i1%%hd= %hd si1= %hd \nsi2= %hd si3= %hd i2 =%d", i1, i1, si1, si2, si3, i2); } Output: i1%d= i1%hd= 4464 si1= -70 si2= si3= -63 i2= g. babic Presentation D 18 9

10 In the previous example little endian byte ordering assumed. Big Endian Least significant byte has highest address Little Endian Byte Ordering Least significant byte has lowest address Example: Variable X has 4-byte content 0x at address 0x1000; thus X includes consecutive bytes at addresses 0x1000, 0x1001, 0x1002 and 0x1003 Big Endian Little Endian 0x1003 0x1002 0x1001 0x x1003 0x1002 0x1001 0x Presentation D 19 Bitwise Operations in C Bitwise operators perform the logical operations and (&), or ( ), xor (^), and 1 s complement (~). Those operations may be applied to any integer data type: signed/unsigned, long, int, short, char and they view arguments as bit vectors Function applied bit-wise All of the properties of Boolean algebra apply & ^ ~ Presentation D 20 10

11 Contrast with Logical Operators in C Logical operators and (&&), or (II) and not (!) view 0 as false, anything nonzero as true Always return 0 or 1 with early termination Examples!0x41 0x00!0x00 0x01 0x69 && 0x55 0x01 0x69 0x55 0x01 Examples with bit level operators &,, ~; no ^ counterpart ~0x41 0xBE ~ ~0x00 0xFF ~ x69 & 0x55 0x & x69 0x55 0x7D Presentation D 21 Shift operations may be applied to any integer data type Left shift: x << y Shift bit-vector x left y positions Throw away extra bits on left Fill with 0 s on right Right shift: x >> y Shift bit-vector x right y positions Throw away extra bits on right Logical shift Fill with 0 s on left Arithmetic shift Shift Operations in C Replicate most significant bit on left Argument X << 3 Logical >>2 Arithmetic>>2 Argument X << 3 Logical >>2 Arithmetic>>2 Undefined behavior if shift amount < 0 or word size Presentation D 22 11

12 Shifts on Signed & Unsigned Integers C performs right shifts on signed integers as arithmetic shifts C performs right shifts on unsigned integers as logical shifts int main() { /*Program Shift.Short.c */ int i1=0x , i2, i3; unsigned u1=0x , u2, u3; i2 = i1 >> 8; u2 = u1 >> 8; i3 = i1 << 8; u3 = u1 << 8; printf("i1= 0x%x i2= 0x%.8X i3= 0x%x", i1, i2, i3); printf("\nu1= 0x%x u2= 0x%.8x u3= 0x%x", u1, u2, u3); } Output: i1= 0x i2= 0xFF i3= 0x u1= 0x u2= 0x u3= 0x g. babic Presentation D 23 Compounded Assignments In addition to arithmetic compounded assignments, such as += and %=, C provides more derivatives by combining computation and assignment together. &= bitwise AND assignment = bitwise OR assignment ^= bitwise exclusive OR assignment <<= left shift assignment >>= right shift assignment Examples: i&= 3 i= i& 3 i <<= 3 i = i << 3 Presentation D 24 12

13 1. a = b = a + b = a = b = a + b = a = b = a + b = a = b = a + b = a = b = a + b = Adding Binary Numbers 1-bit Adder Truth Table Input Output a i b i Carry In i Sum i CarryOut i Let us analyze each case assuming addition of unsigned or signed integers g. babic Presentation D 25 Analysis of Examples on Previous Slide 1. a = As signed a=+19, b=+81, a + b = +100 correct b = As unsigned a=19, b=81, a + b = 100 correct a + b = a = As signed a=-41, b=-47, a + b = -88 correct b = As unsigned a=215, b=209, a + b = 168 incorrect a + b = Final carryout == 1 unsigned overflow 3. a = As signed a=+83, b=+81, a+b = -92 incorrect b = As unsigned a=83, b=81, a+b = 164 correct a + b = Adding 2 positive gives negative signed overflow 4. a = As signed a=+115, b=-47, a+b=+68 correct b = As unsigned a=115, b=209, a+b=68 incorrect a + b = Final carry out == 1 unsigned overflow 5. a = As signed a=-77, b=-111, a+b = +68 incorrect b = As unsigned a=179, b=145, a+b=68 incorrect a + b = Adding 2 negative gives positive signed overflow g. babic 26 Final carry out == 1 unsigned overflow 13

14 UAdd w : Unsigned Addition If operands have w bits, true sum has w+1 bits But standard C addition function ignores (w+1)st bit (final carry output), i.e. (w+1)st bit is truncated. If final carry out is 1, we are left with wrong result overflow UAdd w (u, v) = (u + v) mod 2 w u + v u + v UAdd w (u, v) UAdd w (u,v) u v u v 2 w u v 2 w u v 2 w Overflow case Presentation D 27 TAdd w : Two s Complement Addition Operands: w bits + u v True Sum: w+1 bits u + v Discard carryout: w bits TAdd w (u, v) TAdd w (u,v) u v 2 w 1 u v u v 2 w 1 u v TMin w Negative overflow TMin w u v TMax w TMax w u v Positive overflow Interesting property: 2 s complement addition function is same if operands have same or different signs. Compare with decimal addition! Presentation D 28 14

15 Binary Addition: Summary TAdd w and UAdd w have identical bit-level behavior Signed vs. unsigned addition in C: int s, t, u, v; s = (int) ((unsigned) u + (unsigned) v); t = u + v /* s == t */ How to detect unsigned addition overflow? If the final carryout is 1. Why? If the sum is smaller than any of operands. Why? How to detect 2 s complement addition overflow? If adding 2 negative operands results in positive sum or if adding 2 positive operands results in negative sum. Why? If carryin in the most significant bit is different from final carryout. Why? g. babic Presentation D 29 Logical Operations and Gates Logical operation Complement A 0 1 ~A 1 0 AND A B A and B OR A B A or B XOR A B A xor B Gates Gates are simplest digital logic circuits, and they implement basic logical operations (functions). Gates are designed using few resistors and transistors. Gates are used to build more complex circuits that implement more complex logic functions. g. babic Presentation D 30 15

16 1-bit Adder 32-bit adder can be built out of 32 1-bit adders 1-bit Adder Truth Table CarryIn CarryIn i = Carryout i-1 Input Output a i b i CarryIn i Sum i CarryOut i a a i b i i th 1-bit Adder Sum i Carryout CarryOut i g. babic Presentation D 31 Designing 1-bit Adder A part of 1-bit adder design that calculates carryout C a r r y I n a b C a r r y O u t g. babic Presentation D 32 16

17 2 s Complement Overflow fl1 ~/Cse2421> add2char #include<stdio.h> a=83, a=0x53 b=81, b=0x51 void main() c=-92, c=0xffffffa4 { a+b=164, a+b=0x000000a4 char a=83, b=81, c; printf ("a=%hd, a=0x%hx",a, a); printf (" b=%hd, b=0x%hx",b, b); c=a+b; printf ("\n c=%d, c=0x%x",c, c); printf ("\n a+b=%d, a+b=0x%.8x",a+b, a+b); } g. babic Presentation D bit Ripple Carry Adder 0 a0 b0 Cin + Cout sum0 a1 b1 Cin + Cout sum1 a2 b2 Cin + Cout sum2 a31 b31 Cin + Cout sum31 Carry out g. babic Presentation D 34 17

18 32-bit Subtractor 0 1 A B = A + ( B) = A + ~B + 1 a0 b0 Cin + Cout Result0 a1 b1 Cin + Cout Result1 a2 b2 Cin + Cout Result2 a31 b31 Cin + Cout Result31 CarryOut g. babic Presentation D 35 Which of Statements Below Are Always True? Initialization: int x = foo(); int y = bar(); unsigned ux=x; unsigned uy=y; x < 0 implies x*2 < 0? No if overflow into positive! ux >= 0? Yes. x&7 == 7 implies (x << 30) < 0? Yes. ux > -1? Never. Umax == -1! x > y implies -x < -y? No if y == Tmin! x*x >= 0? No if overflow into negative! x > 0 && y > 0 implies x + y > 0? No if overflow into negative! x >= 0 implies -x <= 0? Yes. x <= 0 implies -x >= 0? No if x == Tmin. (x -x) >> 31 == -1? No if x == 0 ux >> 3 == ux / 8? Yes. x >> 3 == x / 8? No if x negative! int x = -19; y = x >> 3; // y = -3 int z = x / 8; // z = -2 x & (x-1)!= 0? No. x == 0 or x == 1! or x==tmin 36 Presentation D 18

19 Unsigned Multiplication in C Computing exact product of w-bit unsigned numbers x, y Range of results: 0 x * y (2 w 1) 2 = 2 2w 2 w up to 2w bits needed But standard C unsigned multiplication function ignores high order w bits and gives as a result of multiplication lower w bits. C implements modular arithmetic: UMult w (u, v) = u * v mod 2 w u Operands: w bits * v True product: 2*w bits u * v Discard w bits: w bits UMult w (u, v) Presentation D 37 Computing exact product of w-bit 2 s complement numbers x, y Range of results: min: x *y ( 2 w 1 )*(2 w 1 1) = 2 2w w 1 up to 2w 2 bits max: x *y ( 2 w 1 ) 2 Signed Multiplication in C = 2 2w 2 up to 2w 1 bits As for unsigned, standard C signed multiplication function ignores high order w bits. u Operands: w bits * v True product: 2*w bits u * v Discard w bits: w bits TMult w (u, v) Although some of ignored bits are different for signed vs. unsigned multiplication, lower w bits are the same. But, how do we figure out if lower w bits are the complete product or we have lost some significant bit values in higher w bits? Presentation D 38 19

20 Multiplication Examples in C Below shown are three examples of multiplication of two 3-bit unsigned and three examples of two 2 s complement numbers with identical bit patterns. Although the bit-level representations of the full products may differ, those of the truncated product are identical for signed and unsigned multiplication. Mode x y x*y Truncated x*y unsigned 5 10 = = = = s comp = = = = unsigned 4 10 = = = = s comp = = = = unsigned 3 10 = = = = s comp 3 10 = = = = 1 10 g. babic Presentation D 39 Mixing Integer Types: Example 3 int main() { int i2; long i3,i4; short si1 = -1000; i2= si1*si1*si1*si1*si1; i3= si1*si1*si1*si1*si1; i4=si1; i4= i4*si1*si1*si1*si1; printf("i2%%d= %d", i2); printf("\ni2%%hd= %hd", i2); printf("\ni2%%ld= %ld", i2); printf("\ni3%%d= %d", i3); printf("\ni3%%hd= %hd", i3); printf("\ni3%%ld= %ld", i3); printf("\ni4%%d= %d", i4); printf("\ni4%%hd= %hd", i4); printf("\ni4%%ld= %ld", i4);} fl1 ~/Cse2421> MixInt1 i2%d= i2%hd= i2%ld= i3%d= i3%hd= i3%ld= i4%d= i4%hd= i4%ld=

21 Power-of-2 Multiply Using Shifts Operation u << k (left shift) is equivalent to u *2 k for both signed and unsigned. Most machines shift and add much faster than multiply and if one of operands is constant, compilers generate code where an multiplication is replaced by shifts and adds. Examples: x = u * 8 could be compiled as: x = u << 3 x = u * 24 could be compiled as: x = (u << 5) (u<<3) //There is a better way? x= u * 12 could be compiled as: x = (u<<1 + u) << 2 g. babic Presentation D 41 Power-of-2 Divide Using Shifts Divide is also much slow than shift. Quotient of an unsigned integer by power of 2 is equivalent to logical right shift, i.e. u >> k gives u / 2 k. Division Computed Hex Binary x B 6D x >> D B x >> B x >> B Similarly, a quotient of signed integer by power of 2 would be equivalent to arithmetic right shift, i.e. u >> k would give u / 2 k. Arithmetic shift works correct for positive numbers (as logical shift does for unsigned), but for negative integers a result rounds in wrong direction. Division Computed Hex Binary y C y >> E y >> FC y >> FF C What is a correction for negative integers? g. babic Presentation D 42 21

22 Multiplication Multiplication is more complicated than addition and it can be accomplished by shifting and additions. But more time and more area required Example of unsigned multiplication mimicking decimal multiply: 5-bit multiplicand = bit multiplier = = But, this algorithm is very impractical to implement because of a problem to perform addition of many operands at once. g. babic Presentation D 43 Unsigned Integers Multiplication The multiplication can be done with intermediate additions. We introduce Product with a double number of bits initialized by multiplier in lower half and 0 s in upper half. The same example: multiplicand Intermediate Product initially Add multiplicand since Product bit 0 = Shift Product right; Step 1 done Add since Product bit 0 = Shift Product right; Step 2 done Shift Product right, no addition bit=0; Step 3 done Shift Product right, no addition bit=0; Step 4 done Add since Product bit 0 = Shift Product right, Step 5 done Finale result in Product = = g. babic Presentation D 44 22

23 Unsigned Integer Multiplication Multiplicand & Multiplier are w-bit unsigned integers. Initially, 2w-bit Product has Multiplier in its w lower bits and zeros in its w higher bits. == 1 Start Test Product bit 0 == 0 Add Multiplicand to the left half of Product and store the result to the left half of Product Shift Product 1-bit right; Shift in the final carry out from the last addition Shift Product 1-bit logical right w repetitions? No Yes g. babic Presentation D 45 Result in Product Register Multiplication of 2 s Complement Integers A simple algorithm that uses unsigned integer multiplication: If needed, convert to positive integer any negative operand and remember original signs Perform multiplication of unsigned integers Negate product if original signs disagree This algorithm is not simple to implement since: it has to account in advance about signs, if needed, convert operands from negative to positive integers, if needed, convert result back to negative integer at the end Booth s algorithm for 2 s complement multiplication doesn t require converting operands between negative and positive integers. g. babic Presentation F 46 23

24 Booth s Algorithm Start Subtract Multiplicand from the left half of Product and store the result to the left half of Product == 01 == 10 Test Product bit 0 and last time shifted out bit == 00 or 11 Add Multiplicand to the left half of Product and store the result to the left half of Product Shift Product 1-bit arithmetic right Multiplicand & Multiplier are w-bit signed integers. Initially, 2w-bit Product has the Multiplier in its w lower bits and zeros in its w higher bits. w repetitions? g. babic 47 Result in Product Register Yes No Booth s Algorithm: Example A 6-bit (signed) multiplicand = ; Note = bit (signed) multiplier = Product register assumed for step subtract (i.e. add ) shift step 1. ends add shift step 2. ends subtract shift step 3. ends 11 - no arithmetic shift step 4. ends 11 - no arithmetic shift step 5. ends g. babic Presentation D 48 24

25 Booth s Algorithm: Example A (continued) shift step 5. ends (repeated line) add shift step 6. ends Product = = = - (256+63) = Note, that Booth s algorithm has nice property that we do not have to worry in advance about signs of operands. It can be shown (by example, see Example B next)) that the algorithm produces a product with incorrect sign if the multiplicand is Tmin = ; thus an update to the algorithm should be made for that case. g. babic Presentation D 49 Booth s Algorithm: Example B 6-bit (signed) multiplicand = ; Note = bit (signed) multiplier = Product register assumed for step subtract (i.e. add ) shift step 1. ends add shift step 2. ends subtract shift step 3. ends 11 - no arithmetic shift step 4. ends 11 - no arithmetic shift step 5. ends 11 - no arithmetic shift step 6. ends Product = = instead of

Lecture 5-6: Bits, Bytes, and Integers

Lecture 5-6: Bits, Bytes, and Integers CSCI-UA.0201-003 Computer Systems Organization Lecture 5-6: Bits, Bytes, and Integers Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Slides adapted from: Jinyang Li Bryant and O Hallaron

More information

Systems Programming and Computer Architecture ( )

Systems Programming and Computer Architecture ( ) Systems Group Department of Computer Science ETH Zürich Systems Programming and Computer Architecture (252-0061-00) Timothy Roscoe Herbstsemester 2016 1 3: Integers in C Computer Architecture and Systems

More information

Bits, Bytes, and Integers

Bits, Bytes, and Integers Bits, Bytes, and Integers with contributions from Dr. Bin Ren, College of William & Mary 1 Bits, Bytes, and Integers Representing information as bits Bit-level manipulations Integers Representation: unsigned

More information

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

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?

More information

Integers. Dr. Steve Goddard Giving credit where credit is due

Integers. Dr. Steve Goddard   Giving credit where credit is due CSCE 23J Computer Organization Integers Dr. Steve Goddard goddard@cse.unl.edu http://cse.unl.edu/~goddard/courses/csce23j Giving credit where credit is due Most of slides for this lecture are based on

More information

Arithmetic and Bitwise Operations on Binary Data

Arithmetic and Bitwise Operations on Binary Data Arithmetic and Bitwise Operations on Binary Data CSCI 2400: Computer Architecture ECE 3217: Computer Architecture and Organization Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides

More information

Topics of this Slideset. CS429: Computer Organization and Architecture. Encoding Integers: Unsigned. C Puzzles. Integers

Topics of this Slideset. CS429: Computer Organization and Architecture. Encoding Integers: Unsigned. C Puzzles. Integers Topics of this Slideset CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Science University of Texas at Austin Last updated: July 5, 2018 at 11:55 Numeric Encodings:

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Science University of Texas at Austin Last updated: July 5, 2018 at 11:55 CS429 Slideset 3: 1 Topics of this Slideset

More information

Jin-Soo Kim Systems Software & Architecture Lab. Seoul National University. Integers. Spring 2019

Jin-Soo Kim Systems Software & Architecture Lab. Seoul National University. Integers. Spring 2019 Jin-Soo Kim (jinsoo.kim@snu.ac.kr) Systems Software & Architecture Lab. Seoul National University Integers Spring 2019 4190.308: Computer Architecture Spring 2019 Jin-Soo Kim (jinsoo.kim@snu.ac.kr) 2 A

More information

Systems 1. Integers. Unsigned & Twoʼs complement. Addition, negation, multiplication

Systems 1. Integers. Unsigned & Twoʼs complement. Addition, negation, multiplication Systems 1 Integers Topics Numeric Encodings Unsigned & Twoʼs complement Programming Implications C promotion rules Basic operations Addition, negation, multiplication Programming Implications Consequences

More information

Representing and Manipulating Integers. Jo, Heeseung

Representing and Manipulating Integers. Jo, Heeseung Representing and Manipulating Integers Jo, Heeseung Unsigned Integers Encoding unsigned integers B [ bw 1, bw 2,..., b0 ] x = 0000 0111 1101 0011 2 D( B) w 1 b i i 0 2 i D(x) = 2 10 + 2 9 + 2 8 + 2 7 +

More information

Integers Sep 3, 2002

Integers Sep 3, 2002 15-213 The course that gives CMU its Zip! Topics Numeric Encodings Unsigned & Two s complement Programming Implications C promotion rules Basic operations Integers Sep 3, 2002 Addition, negation, multiplication

More information

Integers. Today. Next time. ! Numeric Encodings! Programming Implications! Basic operations. ! Floats

Integers. Today. Next time. ! Numeric Encodings! Programming Implications! Basic operations. ! Floats Integers Today! Numeric Encodings! Programming Implications! Basic operations! Programming Implications Next time! Floats Fabián E. Bustamante, 2007 Integers in C! C supports several integral data types

More information

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

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

More information

CS140 Lecture 08: Data Representation: Bits and Ints. John Magee 13 February 2017

CS140 Lecture 08: Data Representation: Bits and Ints. John Magee 13 February 2017 CS140 Lecture 08: Data Representation: Bits and Ints John Magee 13 February 2017 Material From Computer Systems: A Programmer's Perspective, 3/E (CS:APP3e) Randal E. Bryant and David R. O'Hallaron, Carnegie

More information

Computer Systems CEN591(502) Fall 2011

Computer Systems CEN591(502) Fall 2011 Computer Systems CEN591(502) Fall 2011 Sandeep K. S. Gupta Arizona State University 4 th lecture Data representation in computer systems (Slides adapted from CSAPP book) Announcements Programming assignment

More information

CS 33. Data Representation, Part 2. CS33 Intro to Computer Systems VII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

CS 33. Data Representation, Part 2. CS33 Intro to Computer Systems VII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. CS 33 Data Representation, Part 2 CS33 Intro to Computer Systems VII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. Signed Integers Two s complement b w-1 = 0 Þ non-negative number value = b

More information

ICS Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2

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

More information

Arithmetic and Bitwise Operations on Binary Data

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

More information

Bits, Bytes, and Integers Part 2

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:

More information

Bits, Bytes and Integers

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

More information

CS 33. Data Representation, Part 2. CS33 Intro to Computer Systems VIII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Data Representation, Part 2. CS33 Intro to Computer Systems VIII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Data Representation, Part 2 CS33 Intro to Computer Systems VIII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Numeric Ranges Unsigned Values UMin = 0 000 0 UMax = 2 w 1 111 1 Two s Complement

More information

BITS, BYTES, AND INTEGERS

BITS, BYTES, AND INTEGERS BITS, BYTES, AND INTEGERS CS 045 Computer Organization and Architecture Prof. Donald J. Patterson Adapted from Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition ORIGINS

More information

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Integers II. CSE 351 Autumn Instructor: Justin Hsia Integers II CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/557/

More information

Foundations of Computer Systems

Foundations of Computer Systems 18-600 Foundations of Computer Systems Lecture 3: Bits, Bytes, and Integers September 6, 2017 Required Reading Assignment: Chapter 2 of CS:APP (3 rd edition) by Randy Bryant & Dave O Hallaron Assignments

More information

Bits, Bytes, and Integers August 26, 2009

Bits, Bytes, and Integers August 26, 2009 15-213 The Class That Gives CMU Its Zip! Bits, Bytes, and Integers August 26, 2009 Topics Representing information as bits Bit-level manipulations Boolean algebra Expressing in C Representations of Integers

More information

Integer Arithmetic. CS 347 Lecture 03. January 20, 1998

Integer Arithmetic. CS 347 Lecture 03. January 20, 1998 Integer Arithmetic CS 347 Lecture 03 January 20, 1998 Topics Numeric Encodings Unsigned & Two s complement Programming Implications C promotion rules Consequences of overflow Basic operations Addition,

More information

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Integers II. CSE 351 Autumn Instructor: Justin Hsia Integers II CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun http://xkcd.com/571/

More information

Bits, Bytes and Integers Part 1

Bits, Bytes and Integers Part 1 Bits, Bytes and Integers Part 1 15-213/18-213/15-513: Introduction to Computer Systems 2 nd Lecture, Jan. 18, 2018 Instructors: Franz Franchetti Seth Copen Goldstein Brian Railing 1 Announcements Waitlist

More information

Manipulating Integers

Manipulating Integers Manipulating Integers Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu)

More information

Representa7on of integers: unsigned and signed Conversion, cas7ng Expanding, trunca7ng Addi7on, nega7on, mul7plica7on, shiaing

Representa7on of integers: unsigned and signed Conversion, cas7ng Expanding, trunca7ng Addi7on, nega7on, mul7plica7on, shiaing Today s Topics Representa7on of integers: unsigned and signed Conversion, cas7ng Expanding, trunca7ng Addi7on, nega7on, mul7plica7on, shiaing CSE351 Inaugural Edi7on Spring 2010 1 Encoding Integers C short

More information

Integers II. CSE 351 Autumn 2018

Integers II. CSE 351 Autumn 2018 Integers II CSE 351 Autumn 2018 Instructor: Teaching Assistants: Justin Hsia Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson Sophie Tian Teagan

More information

Bits, Bytes, and Integers

Bits, Bytes, and Integers Bits, Bytes, and Integers B&O Readings: 2.1-2.3 CSE 361: Introduc=on to Systems So@ware Instructor: I- Ting Angelina Le e Note: these slides were originally created by Markus Püschel at Carnegie Mellon

More information

Bits and Bytes: Data Presentation Mohamed Zahran (aka Z)

Bits and Bytes: Data Presentation Mohamed Zahran (aka Z) CSCI-UA.0201 Computer Systems Organization Bits and Bytes: Data Presentation Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Some slides adapted and modified from: Clark Barrett Jinyang

More information

Representing and Manipulating Integers Part I

Representing and Manipulating Integers Part I Representing and Manipulating Integers Part I Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Introduction The advent of the digital age Analog

More information

CS 270: Computer Organization. Integer Arithmetic Operations

CS 270: Computer Organization. Integer Arithmetic Operations CS 270: Computer Organization Integer Arithmetic Operations Instructor: Professor Stephen P. Carl Unsigned Addition Operands: w bits True Sum: w+1 bits u + v u + v Discard Carry UAdd w (u, v) Standard

More information

CS 33. Data Representation, Part 1. CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Data Representation, Part 1. CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Data Representation, Part 1 CS33 Intro to Computer Systems VII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Number Representation Hindu-Arabic numerals developed by Hindus starting in

More information

Bitwise Data Manipulation. Bitwise operations More on integers

Bitwise Data Manipulation. Bitwise operations More on integers Bitwise Data Manipulation Bitwise operations More on integers bitwise operators ex Bitwise operators on fixed-width bit vectors. AND & OR XOR ^ NOT ~ 01101001 & 01010101 01000001 01101001 01010101 01101001

More information

Representing Integers. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Representing Integers. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Representing Integers Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Unsigned Integers Encoding unsigned integers B [ bw 1, bw2,..., b0 ] x = 0000

More information

Computer Organization: A Programmer's Perspective

Computer Organization: A Programmer's Perspective A Programmer's Perspective Bits, Bytes, Nibbles, Words and Strings Gal A. Kaminka galk@cs.biu.ac.il Topics Why bits? Why 0/1? Basic terms: Bits, Bytes, Nibbles, Words Representing information as bits Characters

More information

Integer Representation

Integer Representation Integer Representation Representation of integers: unsigned and signed Modular arithmetic and overflow Sign extension Shifting and arithmetic Multiplication Casting 1 Fixed- width integer encodings Unsigned

More information

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Instructor: Rob Bergen Applied Computer Science University of Winnipeg Announcements Website is up

More information

Page # CISC360. Integers Sep 11, Encoding Integers Unsigned. Encoding Example (Cont.) Topics. Twoʼs Complement. Sign Bit

Page # CISC360. Integers Sep 11, Encoding Integers Unsigned. Encoding Example (Cont.) Topics. Twoʼs Complement. Sign Bit Topics CISC3 Integers Sep 11, 28 Nmeric Encodings Unsigned & Twoʼs complement Programming Implications C promotion rles Basic operations Addition, negation, mltiplication Programming Implications Conseqences

More information

Representing Integers

Representing Integers Representing Integers Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu)

More information

Page 1 CISC360. Encoding Integers Unsigned. Integers Sep 8, Numeric Ranges. Encoding Example (Cont.)

Page 1 CISC360. Encoding Integers Unsigned. Integers Sep 8, Numeric Ranges. Encoding Example (Cont.) CISC3 Integers Sep, 9 Encoding Integers Unsigned w 1 BU(X) = x i i i= short int x = 1513; short int y = -1513; Twoʼs Complement w BT(X) = x w 1 w 1 + x i i i= Sign Bit Decimal Hex Binary x 1513 3B D 11111

More information

Number Systems and Computer Arithmetic

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

More information

CS/COE 0447 Example Problems for Exam 2 Spring 2011

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

More information

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

Bits and Bytes. Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions

Bits and Bytes. Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions Bits and Bytes Topics Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions Bit-level manipulations Boolean algebra Expressing

More information

Page 1. Where Have We Been? Chapter 2 Representing and Manipulating Information. Why Don t Computers Use Base 10?

Page 1. Where Have We Been? Chapter 2 Representing and Manipulating Information. Why Don t Computers Use Base 10? Where Have We Been? Class Introduction Great Realities of Computing Int s are not Integers, Float s are not Reals You must know assembly Memory Matters Performance! Asymptotic Complexity It s more than

More information

Chapter 3 Arithmetic for Computers

Chapter 3 Arithmetic for Computers Chapter 3 Arithmetic for Computers 1 Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: Implementing the Architecture operation

More information

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

More information

Binary Adders: Half Adders and Full Adders

Binary Adders: Half Adders and Full Adders Binary Adders: Half Adders and Full Adders In this set of slides, we present the two basic types of adders: 1. Half adders, and 2. Full adders. Each type of adder functions to add two binary bits. In order

More information

Chapter 4. Operations on Data

Chapter 4. Operations on Data Chapter 4 Operations on Data 1 OBJECTIVES After reading this chapter, the reader should be able to: List the three categories of operations performed on data. Perform unary and binary logic operations

More information

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting) 2.1 Unit 2 Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting) 2.2 Skills & Outcomes You should know and be able to apply the following skills with confidence Perform addition & subtraction

More information

Arithmetic Operations

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

More information

Why Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation

Why Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation Lecture 2 Bits and Bytes Topics! Why bits?! Representing information as bits " Binary/Hexadecimal " Byte representations» numbers» characters and strings» Instructions! Bit-level manipulations " Boolean

More information

Basic Arithmetic (adding and subtracting)

Basic Arithmetic (adding and subtracting) Basic Arithmetic (adding and subtracting) Digital logic to show add/subtract Boolean algebra abstraction of physical, analog circuit behavior 1 0 CPU components ALU logic circuits logic gates transistors

More information

Microcomputers. Outline. Number Systems and Digital Logic Review

Microcomputers. Outline. Number Systems and Digital Logic Review Microcomputers Number Systems and Digital Logic Review Lecture 1-1 Outline Number systems and formats Common number systems Base Conversion Integer representation Signed integer representation Binary coded

More information

REMEMBER TO REGISTER FOR THE EXAM.

REMEMBER TO REGISTER FOR THE EXAM. REMEMBER TO REGISTER FOR THE EXAM http://tenta.angstrom.uu.se/tenta/ Floating point representation How are numbers actually stored? Some performance consequences and tricks Encoding Byte Values Byte =

More information

Why Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation

Why Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation Lecture 2 Bits and Bytes Topics Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions Bit-level manipulations Boolean algebra

More information

Computer Architecture Set Four. Arithmetic

Computer Architecture Set Four. Arithmetic Computer Architecture Set Four Arithmetic Arithmetic Where we ve been: Performance (seconds, cycles, instructions) Abstractions: Instruction Set Architecture Assembly Language and Machine Language What

More information

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

CS107, Lecture 3 Bits and Bytes; Bitwise Operators CS107, Lecture 3 Bits and Bytes; Bitwise Operators reading: Bryant & O Hallaron, Ch. 2.1 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons Attribution

More information

Bits, Bytes, and Integers. Bits, Bytes, and Integers. The Decimal System and Bases. Everything is bits. Converting from Decimal to Binary

Bits, Bytes, and Integers. Bits, Bytes, and Integers. The Decimal System and Bases. Everything is bits. Converting from Decimal to Binary with contribtions from Dr. Bin Ren, College of William & Mary Addition, negation, mltiplication, shifting 1 Everything is bits The Decimal System and Bases Each bit is or 1 By encoding/interpreting sets

More information

Advanced Computer Architecture-CS501

Advanced Computer Architecture-CS501 Advanced Computer Architecture Lecture No. 34 Reading Material Vincent P. Heuring & Harry F. Jordan Chapter 6 Computer Systems Design and Architecture 6.1, 6.2 Summary Introduction to ALSU Radix Conversion

More information

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other Kinds Of Data CHAPTER 3 DATA REPRESENTATION Numbers Integers Unsigned Signed Reals Fixed-Point Floating-Point Binary-Coded Decimal Text ASCII Characters Strings Other Graphics Images Video Audio Numbers

More information

EE 109 Unit 6 Binary Arithmetic

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

More information

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26) Lecture Topics Today: Integer Arithmetic (P&H 3.1-3.4) Next: continued 1 Announcements Consulting hours Introduction to Sim Milestone #1 (due 1/26) 2 1 Overview: Integer Operations Internal representation

More information

Module 2: Computer Arithmetic

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

More information

COMP2611: Computer Organization. Data Representation

COMP2611: Computer Organization. Data Representation COMP2611: Computer Organization Comp2611 Fall 2015 2 1. Binary numbers and 2 s Complement Numbers 3 Bits: are the basis for binary number representation in digital computers What you will learn here: How

More information

Bits and Bytes January 13, 2005

Bits and Bytes January 13, 2005 15-213 The Class That Gives CMU Its Zip! Topics Bits and Bytes January 13, 25 Why bits? Representing information as bits Binary / Hexadecimal Byte representations» Numbers» Characters and strings» Instructions

More information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

Binary Values. CSE 410 Lecture 02

Binary Values. CSE 410 Lecture 02 Binary Values CSE 410 Lecture 02 Lecture Outline Binary Decimal, Binary, and Hexadecimal Integers Why Place Value Representation Boolean Algebra 2 First: Why Binary? Electronic implementation Easy to store

More information

C Puzzles! Taken from old exams. Integers Sep 3, Encoding Integers Unsigned. Encoding Example (Cont.) The course that gives CMU its Zip!

C Puzzles! Taken from old exams. Integers Sep 3, Encoding Integers Unsigned. Encoding Example (Cont.) The course that gives CMU its Zip! 15-13 The corse that gies CMU its Zip! Topics class3.ppt Integers Sep 3,! Nmeric Encodings " Unsigned & Two s complement! Programming Implications " C promotion rles! Basic operations " Addition, negation,

More information

Chapter 3: part 3 Binary Subtraction

Chapter 3: part 3 Binary Subtraction Chapter 3: part 3 Binary Subtraction Iterative combinational circuits Binary adders Half and full adders Ripple carry and carry lookahead adders Binary subtraction Binary adder-subtractors Signed binary

More information

CS367 Test 1 Review Guide

CS367 Test 1 Review Guide CS367 Test 1 Review Guide This guide tries to revisit what topics we've covered, and also to briefly suggest/hint at types of questions that might show up on the test. Anything on slides, assigned reading,

More information

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

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.

More information

Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators. Portability: Printing Numbers Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

More information

Simple Data Types in C. Alan L. Cox

Simple Data Types in C. Alan L. Cox Simple Data Types in C Alan L. Cox alc@rice.edu Objectives Be able to explain to others what a data type is Be able to use basic data types in C programs Be able to see the inaccuracies and limitations

More information

Number Systems CHAPTER Positional Number Systems

Number Systems CHAPTER Positional Number Systems CHAPTER 2 Number Systems Inside computers, information is encoded as patterns of bits because it is easy to construct electronic circuits that exhibit the two alternative states, 0 and 1. The meaning of

More information

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8 Data Representation At its most basic level, all digital information must reduce to 0s and 1s, which can be discussed as binary, octal, or hex data. There s no practical limit on how it can be interpreted

More information

SIGNED AND UNSIGNED SYSTEMS

SIGNED AND UNSIGNED SYSTEMS EE 357 Unit 1 Fixed Point Systems and Arithmetic Learning Objectives Understand the size and systems used by the underlying HW when a variable is declared in a SW program Understand and be able to find

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

CSCI2467: Systems Programming Concepts

CSCI2467: Systems Programming Concepts CSCI2467: Systems Programming Concepts Slideset 2: Information as Data (CS:APP Chap. 2) Instructor: M. Toups Spring 2018 Course updates datalab out today! - due after Mardi gras... - do not wait until

More information

MIPS Integer ALU Requirements

MIPS Integer ALU Requirements MIPS Integer ALU Requirements Add, AddU, Sub, SubU, AddI, AddIU: 2 s complement adder/sub with overflow detection. And, Or, Andi, Ori, Xor, Xori, Nor: Logical AND, logical OR, XOR, nor. SLTI, SLTIU (set

More information

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-2700: Digital Logic Design Winter Notes - Unit 4. hundreds.

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-2700: Digital Logic Design Winter Notes - Unit 4. hundreds. UNSIGNED INTEGER NUMBERS Notes - Unit 4 DECIMAL NUMBER SYSTEM A decimal digit can take values from to 9: Digit-by-digit representation of a positive integer number (powers of ): DIGIT 3 4 5 6 7 8 9 Number:

More information

Tailoring the 32-Bit ALU to MIPS

Tailoring the 32-Bit ALU to MIPS Tailoring the 32-Bit ALU to MIPS MIPS ALU extensions Overflow detection: Carry into MSB XOR Carry out of MSB Branch instructions Shift instructions Slt instruction Immediate instructions ALU performance

More information

Integer Representation

Integer Representation Integer Representation Announcements assign0 due tonight assign1 out tomorrow Labs start this week SCPD Note on ofce hours on Piazza Will get an email tonight about labs Goals for Today Introduction to

More information

Arithmetic Processing

Arithmetic Processing CS/EE 5830/6830 VLSI ARCHITECTURE Chapter 1 Basic Number Representations and Arithmetic Algorithms Arithmetic Processing AP = (operands, operation, results, conditions, singularities) Operands are: Set

More information

Integer Representation Floating point Representation Other data types

Integer Representation Floating point Representation Other data types Chapter 2 Bits, Data Types & Operations Integer Representation Floating point Representation Other data types Why do Computers use Base 2? Base 10 Number Representation Natural representation for human

More information

Chapter 4 Arithmetic Functions

Chapter 4 Arithmetic Functions Logic and Computer Design Fundamentals Chapter 4 Arithmetic Functions Charles Kime & Thomas Kaminski 2008 Pearson Education, Inc. (Hyperlinks are active in View Show mode) Overview Iterative combinational

More information

Arithmetic Logic Unit

Arithmetic Logic Unit Arithmetic Logic Unit A.R. Hurson Department of Computer Science Missouri University of Science & Technology A.R. Hurson 1 Arithmetic Logic Unit It is a functional bo designed to perform "basic" arithmetic,

More information

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

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.

More information

Data Types. Data Types. Integer Types. Signed Integers

Data Types. Data Types. Integer Types. Signed Integers Data Types Data Types Dr. TGI Fernando 1 2 The fundamental building blocks of any programming language. What is a data type? A data type is a set of values and a set of operations define on these values.

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

COMP 303 Computer Architecture Lecture 6

COMP 303 Computer Architecture Lecture 6 COMP 303 Computer Architecture Lecture 6 MULTIPLY (unsigned) Paper and pencil example (unsigned): Multiplicand 1000 = 8 Multiplier x 1001 = 9 1000 0000 0000 1000 Product 01001000 = 72 n bits x n bits =

More information

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

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

More information

Operators & Expressions

Operators & Expressions Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.

More information

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS C H A P T E R 6 DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS OUTLINE 6- Binary Addition 6-2 Representing Signed Numbers 6-3 Addition in the 2 s- Complement System 6-4 Subtraction in the 2 s- Complement

More information