Bits, Bytes, and Integers. Data Representa+on: Base- 2 number representa+on. Binary Representa+ons. Encoding Byte Values. Example Data Representa+ons

Size: px
Start display at page:

Download "Bits, Bytes, and Integers. Data Representa+on: Base- 2 number representa+on. Binary Representa+ons. Encoding Byte Values. Example Data Representa+ons"

Transcription

1 Bits, Bytes, and Data Representa+on: Bits, Bytes, and CSci 1 - Machine Architectre and Organiza+on Professor Pen- Chng Yew Bit- level manipla+ons Representa9on: nsigned and signed Expanding, trnca9ng Addi9on, nega9on, ml9plica9on, shicing Smmary With sides from Randy Bryant and Dave O Hallaron 1 Binary Representa+ons Each bit is or 1 By encoding/interpre+ng sets of bits in varios ways Compters determine what to do (instrc9ons), and represent and maniplate nmbers, sets, strings, etc Why bits? Electronic Implementa+on Easy to store with bistable elements, e.g. switches, transistors, Reliably transmiked on noisy and inaccrate wires 1.1V.9V 1 Base- nmber representa+on Decimal to Binary Represent 15 1 as 111 Represent 1. 1 as 1.11[11] Represent 1.51 X 1 as 1.11 X 7 Binary to Decimal Represent 111 as 1 Represent as Represent X 3 as 1.35 X 1 1.V.V 3 Encoding Byte Vales Byte bits Binary to Decimal: 1 to 551 Hexadecimal: 1 to 1 Base 1 nmber representa9on Use characters to 9 and A to F Write FA1D37B1 in C as xfa1d37b xfa1d37b xfa1d37b Hex Decimal Binary A 1 11 B C 1 11 D E F Example Data Representa+ons C Data Type Typical 3- bit Typical - bit x- char short int long float doble long doble 1/1 pointer 5 1

2 Today: Bits, Bytes, and Boolean Algebra Bit- level manipla+ons Representa9on: nsigned and signed Expanding, trnca9ng Addi9on, nega9on, ml9plica9on, shicing Smmary Developed by George Boole in 19th Centry Algebraic representa9on of logic Encode Tre as 1 and False as And Or n A&B 1 when both A1 and B1 n A B 1 when either A1 or B1 Not Exclsive- Or (Xor) n ~A 1 when A n A^B 1 when either A1 or B1, bt not both 7 General Boolean Algebras Represen+ng & Manipla+ng Sets Operate on Bit Vectors Opera9ons applied bitwise 1111 & ^ ~ All of the Proper+es of Boolean Algebra Apply 9 Representa+on Width w bit vector represents sbsets of {,, w 1} a j 1 if j A 1111 A {, 3, 5, } A {,,, } 7531 Opera+ons & Intersec9on 11 {, } Union {,, 3,, 5, } ^ Symmetric difference 1111 {, 3,, 5 } ~ Complement 1111 { 1, 3, 5, 7 } 1 Bit- Level Opera+ons in C Opera+ons &,, ~, ^ Available in C Apply to any integral data type long, int, short, char, nsigned View argments as bit vectors Argments applied bit- wise Examples (char data type 1 byte) ~x1 xbe ~ ~x x ~ x9 & x55 x & x9 x55 x7d Contrast: Logic Opera+ons in C Contrast to Logical Operators &&,,! View as False Anything nonzero as Tre Always retrn or 1 Examples (char data type)!x1 x!x x1!!x1 x1 x9 && x55 x1 x9 x55 x1 11 1

3 Contrast: Logic Opera+ons in C Contrast to Logical Operators &&,,! View as False Anything nonzero as Tre Always retrn or 1 Early termina9on Examples (char data type)!x1 x!x x1!!x1 x1 Watch ot for && vs. & (and vs. ) one of the more common oopsies in C programming x9 && x55 x1 x9 x55 x1 ShiZ Opera+ons LeZ ShiZ: x << y ShiZ bit- vector x lez y posi+ons Throw away extra bits on lez Fill with s on right Right ShiZ: x >> y ShiZ bit- vector x right y posi+ons Throw away extra bits on right Logical shiz Fill with s on lez Arithme+c shiz Replicate most significant bit on lez Undefined Behavior ShiZ amont < or word size Argment x 111 << 3 1 Log. >> 11 Arith. >> 11 Argment x 111 << 3 1 Log. >> 11 Arith. >> Today: Bits, Bytes, and Bit- level manipla+ons Representa+on: nsigned and signed Expanding, trnca9ng Addi9on, nega9on, ml9plica9on, shicing Smmary Smmary Encoding Unsigned and Signed Unsigned (BU) w 1 BU(X) x i i i short int x 1513; short int y -1513; Sign Bit For s complement, most significant bit indicates sign for nonnega+ve 1 for nega+ve In C, data type short is bytes long Two s Complement (BT) w BT(X) x w 1 w 1 + x i i i Decimal Hex Binary x B D y C Sign Bit 15 1 Encoding Example (Binary to Unsigned BU ) x 1513: y -1513: Weight Sm w 1 BU(X) x i i i w BT(X) x w 1 w 1 + x i i i 17 Binary Weight Table x 1 K 1 +1 x 1 K x 1 K 1 +1 x 1 1K x 1 3K 1 +1 x 1 K x 1 1K 1 +1 x 1 5K x 1 51K 1 3

4 Conver+ng Unsigned to Binary (UB) Dividing the nmber repeatedly by n+l the nmber becomes 9? w 1 BU(X) x i i i Same nota+on to ANY nmber system Divide by Nmber Remainder 9 1 Nmeric Ranges Unsigned Vales UMin UMax w Two s Complement Vales Tmin w 1 1 Tmax w Other Vales Mins 1 w Vales for W 1 Decimal Hex Binary UMax TMax 377 7F TMin x x + x 3 + x + x x 9 19 Vales for Different Word Sizes Observa+ons TMin TMax + 1 Asymmetric range UMax * TMax + 1 W 1 3 UMax 55 5,535,9,97,95 1,,7,73,79,551,15 TMax 17 3,77,17,3,7 9,3,37,3,5,775,7 TMin - 1-3,7 -,17,3, - 9,3,37,3,5,775, C Programming #inclde <limits.h> Declares constants, e.g., ULONG_MAX LONG_MAX LONG_MIN Vales plaiorm specific Need to know - > to avoid overflow 1 Unsigned & Signed Integer Vales X BU(X) BT(X) Eqivalence Same encodings for nonnega9ve integer vales Uniqeness Every bit pakern represents niqe integer vale Each representable integer has niqe bit encoding Can Invert Mappings UB(x) BU - 1 (x) Bit pakern for nsigned integer TB(x) BT - 1 (x) Bit pakern for two s comp integer Today: Bits, Bytes, and Bit- level manipla+ons Representa9on: nsigned and signed Conversion, cas+ng Expanding, trnca9ng Addi9on, nega9on, ml9plica9on, shicing Smmary Mapping Between Signed & Unsigned Two s Complement TU Unsigned x TB X BU x Maintain Same Bit Palern Unsigned UT Two s Complement x UB X BT x Maintain Same Bit Palern Mappings between nsigned and two s complement nmbers: keep bit representa+ons and reinterpret 3

5 Mapping Signed Unsigned Mapping Signed Unsigned Bits Signed Unsigned Bits Signed Unsigned TU UT / Rela+on between Signed & Unsigned Two s Complement w 1 x x Large nega+ve weight becomes Large posi+ve weight x TU TB X BU Maintain Same Bit Palern x Unsigned x x x x + w x < 7 Conversion Visalized s Comp. Unsigned Ordering Inversion Nega9ve Big Posi9ve Warning: Can case a lot of confsion and bgs in C!!! s Complement Range TMax 1 TMin UMax UMax 1 TMax + 1 TMax Unsigned Range Signed vs. Unsigned in C Constants By defalt are considered to be signed integers Unsigned if have U as sffix U, 99759U Cas+ng (i.e. conversion) Explicit cas+ng between signed & nsigned same as UT and TU int tx, ty; nsigned x, y; tx (int) x; y (nsigned) ty; Smmary Cas+ng Signed Unsigned: Basic Rles Bit palern is maintained Bt reinterpreted Can have nexpected effects: adding or sbtrac+ng w Expression containing signed and nsigned int int is cast to nsigned!! Implicit cas+ng also occrs via assignments and procedre calls tx x; y ty;

6 Today: Bits, Bytes, and Bit- level manipla+ons Representa9on: nsigned and signed Expanding, trnca+ng Addi9on, nega9on, ml9plica9on, shicing Smmary Sign Extension Task: Given w- bit signed integer x Convert it to w+k- bit integer with same vale Rle: Make k copies of sign bit: X ʹ x w 1,, x w 1, x w 1, x w,, x k copies of MSB X w 3 X ʹ k w 33 Sign Extension Example short int x 1513; int ix (int) x; short int y -1513; int iy (int) y; Conver+ng from smaller to larger integer data type C atoma+cally performs sign extension Decimal Hex Binary x B D ix B D y C iy C Smmary: Expanding, Trnca+ng: Basic Rles Expanding (e.g., short int to int) Unsigned: zeros added Signed: sign extension Both yield expected reslt Trnca+ng (e.g., nsigned to nsigned short) Unsigned/signed: bits are trncated Reslt reinterpreted Unsigned: mod opera9on Signed: similar to mod For small nmbers yields expected behavior 3 35 Today: Bits, Bytes, and Bit- level manipla+ons Representa9on: nsigned and signed Expanding, trnca9ng Addi+on, nega+on, ml+plica+on, shizing Smmary Nega+on: Complement & Increment Claim: Following Holds for s Complement ~x + 1 -x Two s Complement Observa9on: ~x + x x ~x

7 Complement & Increment Examples x 1513 Decimal Hex Binary x B D ~x -151 C ~x C y C Unsigned Addi+on Operands: w bits + v Tre Sm: w+1 bits + v Discard Carry: w bits UAdd w (, v) x Decimal Hex Binary ~ ~+1 q What is - TMIN? (pp.37) Standard Addi+on Fnc+on Ignores carry otpt Implements Modlar Arithme+c s UAdd w (, v) ( + v) mod w + v + v < w UAdd w (,v) + v w + v w 3 39 Visalizing (Mathema+cal) Integer Addi+on Visalizing Unsigned Addi+on Integer Addi+on - bit integers, v Compte tre sm Add (, v) Vales increase linearly with and v Forms planar srface Add (, v) Integer Addition v Wraps Arond If tre sm w At most once Tre Sm w+1 w Overflow Modlar Sm Overflow UAdd (, v) v 1 Two s Complement Addi+on Operands: w bits Tre Sm: w+1 bits TAdd and UAdd have Iden+cal Bit- Level Behavior Signed vs. nsigned addi9on in C: int s, t,, v; s (int) ((nsigned) + (nsigned) v); t + v Will give s t + v + v Discard Carry: w bits TAdd w (, v) TAdd Overflow Fnc+onality Tre sm reqires w+1 bits Drop off Most Significant Bit (MSB) Treat remaining bits as s comp. integer (w) 1 (w 1) (w 1) 1 Tre Sm w PosOver NegOver TAdd Reslt

8 Visalizing s Complement Addi+on Characterizing TAdd Vales - bit two s comp. Range from - to +7 Wraps Arond If sm w 1 Becomes nega9ve At most once If sm < w 1 Becomes posi9ve At most once NegOver TAdd (, v) v PosOver Fnc+onality Tre sm reqires w+1 bits Drop off MSB Treat remaining bits as s comp. integer TAdd(, v) > v < Nega9ve Overflow < > Posi9ve Overflow + v + w 1 w + v < TMin w (NegOver) TAdd w (,v) + v TMin w + v TMax w + v w 1 TMax w < + v (PosOver) 5 Ml+plica+on Comp+ng Exact Prodct of w- bit nmbers x, y Either signed or nsigned Ranges Unsigned: Up to w bits Reslt range: x * y ( w 1) w w Two s complement min (nega9ve) : Up to w 1 bits Reslt range: x * y ( w 1 )*( w 1 1) w + w 1 Two s complement max (posi9ve): Up to w bits, bt only for (TMin w ) Reslt range: x * y ( w 1 ) w Maintaining Exact Reslts Wold need to keep expanding word size with each prodct compted Done in socware by arbitrary precision arithme9c packages Unsigned Ml+plica+on in C Operands: w bits Tre Prodct: *w bits Discard w bits: w bits v Standard Ml+plica+on Fnc+on Ignores high order w bits Implements Modlar Arithme+c UMlt w (, v) v mod w * v UMlt w (, v) 7 Signed Ml+plica+on in C Power- of- Ml+ply with ShiZ Operands: w bits Tre Prodct: *w bits Discard w bits: w bits v Standard Ml+plica+on Fnc+on Ignores high order w bits Some of which are different for signed vs. nsigned ml9plica9on Lower bits are the same * v TMlt w (, v) Opera+on << k gives * k Both signed and nsigned Operands: w bits Tre Prodct: w+k bits k k 1 Discard k bits: w bits UMlt w (, k ) TMlt w (, k ) Examples << 3 * << 5 - << 3 ( * 3) ( * ) * Most machines shic and add faster than ml9ply Compiler generates this code atoma9cally * k 9

9 Unsigned Power- of- Divide with ShiZ Qo+ent of Unsigned by Power of >> k gives / k Uses logical shic k Operands: / k 1 Division: Reslt: / k / k Division Compted Hex Binary x B D x >> D B x >> B x >> B Binary Point Signed Power- of- Divide with ShiZ Qo+ent of Signed by Power of x >> k gives x / k Uses arithme9c shic Ok when >, bt ronds wrong direc9on when < k x Binary Point Operands: / k 1 Division: x / k. Reslt: RondDown(x / k ) Division Compted Hex Binary y C y >> E y >> FC y >> C Correct Power- of- Divide Qo+ent of Nega+ve Nmber by Power of Want x / k (Rond Toward ) Compte as (x+ k -1)/ k In C: (x + (1<<k)-1) >> k Biases dividend toward Case 1: No ronding k Dividend: 1 + k Divisor: / k / k Biasing has no effect Binary Point Correct Power- of- Divide (Cont.) Case : Ronding Dividend: Divisor: k x 1 + k / k x / k Biasing adds 1 to final reslt 1 Incremented by Binary Point Incremented by Today: Bits, Bytes, and Arithme+c: Basic Rles Bit- level manipla+ons Representa9on: nsigned and signed Expanding, trnca9ng Addi9on, nega9on, ml9plica9on, shicing Smmary Addi+on: Unsigned/signed: Normal addi9on followed by trncate, same opera9on on bit level Unsigned: addi9on mod w Mathema9cal addi9on + possible sbtrac9on of w Signed: modified addi9on mod w (reslt in proper range) Mathema9cal addi9on + possible addi9on or sbtrac9on of w Ml+plica+on: Unsigned/signed: Normal ml9plica9on followed by trncate, same opera9on on bit level Unsigned: ml9plica9on mod w Signed: modified ml9plica9on mod w (reslt in proper range)

10 Arithme+c: Basic Rles Why Shold I Use Unsigned? LeZ shiz (Ml+plica+on) Unsigned/signed: ml9plica9on by k Always logical lec shic Don t se withot nderstanding implica+ons Easy to make mistakes nsigned i; for (i cnt-; i > ; i--) a[i] + a[i+1]; Right shiz (Division) Unsigned: logical right shic, div (division + rond to zero) by k Signed: arithme9c shic Posi+ve nmbers: div (division + rond to zero) by k Nega+ve nmbers: div (division + rond away from zero) by k Use biasing to fix Can be very sbtle #define DELTA sizeof(int) int i; for (i CNT; i-delta > ; i- DELTA) Con+ng Down with Unsigned Why Shold I Use Unsigned? (cont.) Proper way to se nsigned as loop index nsigned i; for (i cnt-; i < cnt; i--) a[i] + a[i+1]; See Robert Seacord, Secre Coding in C and C++ C Standard garantees that nsigned addi9on will behave like modlar arithme9c 1 à UMax Even beler size_t i; for (i cnt-; i < cnt; i--) a[i] + a[i+1]; Data type size_t defined as nsigned vale with length word size Code will work even if cnt UMax What if cnt is signed and <? 5 Do Use When Performing Modlar Arithme+c Ml9precision arithme9c Do Use When Using Bits to Represent Sets Logical right shic, no sign extension 59 Today: Bits, Bytes, and Bit- level manipla+ons Representa9on: nsigned and signed Expanding, trnca9ng Addi9on, nega9on, ml9plica9on, shicing Smmary Byte- Oriented Memory Organiza+on Programs refer to data by address Conceptally, envision it as a very large array of bytes In reality, it s not, bt can think of it that way An address is like an index into that array and, a pointer variable stores an address F Note: system provides private address spaces to each process Think of a process as a program being exected So, a program can clobber its own data, bt not that of others 1 1

11 Machine Words Any Given Machine Has a Word Size Nominal size of integer- valed data Inclding addresses Many crrent machines se 3 bits ( bytes) words Limits addresses to 3 GB Becoming too small for memory- intensive applica9ons Most high- end systems se bits ( bytes) words Poten9al address space 1. X 1 19 bytes (exabytes) Machines spport ml9ple data formats Frac9ons or ml9ples of word size Always integral nmber of bytes 3 Word- Oriented Memory Organiza+on Addresses Specify Byte Loca+ons Address of first byte in a word Addresses of sccessive words differ by (3- bit) or (- bit) Need to dis+ngish the no+on of address vs. data stored in that address 3-bit Words Addr?? Addr?? Addr?? Addr 1?? -bit Words Addr?? Addr?? Bytes Addr Byte Ordering How shold bytes within a ml+- byte word be ordered in memory? Conven+ons Big Endian: Sn, PPC Mac, Internet Least significant byte has highest address, i.e Most significant byte first Lille Endian: x, ARM processors rnning Android, ios and Windows Least significant byte has lowest address, i.e. Least significant byte first Byte Ordering Example Big Endian Least significant byte has highest address Lille Endian Least significant byte has lowest address Example Variable x has - byte representa9on x1357 Address given by &x is x1 Big Endian Little Endian x1 x11 x1 x x1 x11 x1 x Reading Byte- Reversed Lis+ngs Disassembly Text representa9on of binary machine code Generated by program that reads the machine code Example Fragment Address Instrction Code Assembly Rendition 35: 5b pop %ebx 3: 1 c3 ab 1 add $x1ab,%ebx 3c: 3 bb cmpl $x,x(%ebx) Deciphering Nmbers Vale: x1ab Pad to 3 bits: x1ab Split into bytes: 1 ab Reverse: ab 1 7 Represen+ng int A 1513; IA3, x- D 3B IA3, x- 93 C Sn 3B D int B -1513; Sn C 93 Decimal: 1513 Binary: Hex: 3 B D long int C 1513; IA3 D 3B x- D 3B Two s complement representation (Covered later) Sn 3B D 11

12 Examining Data Representa+ons Code to Print Byte Representa+on of Data Cas9ng pointer to nsigned char * allows treatment as a byte array typedef nsigned char *pointer; void show_bytes(pointer start, size_t len){ size_t i; for (i ; i < len; i++) printf( %p\tx%.x\n",start+i, start[i]); printf("\n"); } Printf directives: %p: Print pointer %x: Print Hexadecimal show_bytes Exec+on Example int a 1513; printf("int a 1513;\n"); show_bytes((pointer) &a, sizeof(int)); Reslt (Linx x-): int a 1513; x7fffb7f71dbc d x7fffb7f71dbd 3b x7fffb7f71dbe x7fffb7f71dbf 9 7 Represen+ng Pointers int B -1513; int *P &B; Sn EF FB C IA3 D F BF x- C 9 EC 7F Represen+ng Strings char S[] "13"; Strings in C Represented by array of characters Each character encoded in ASCII format Linx/Alpha Sn Standard 7- bit encoding of character set Character has code x3 3 3 Digit i has code x3+i 3 3 String shold be nll- terminated 3 3 Final character Compa+bility Byte ordering not an isse Different compilers & machines assign different loca9ons to objects Even get different reslts each 9me rn program

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

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

Csci 2021 Class Web Pages. Data Representa?on: Bits, Bytes, and Integers. Binary Representa?ons. Bits, Bytes, and Integers

Csci 2021 Class Web Pages. Data Representa?on: Bits, Bytes, and Integers. Binary Representa?ons. Bits, Bytes, and Integers Csci 1 Class Web Pages Departmental Class Web Page: Pblic access withot login Corse syllabs, schedle, lectre notes, other sefl info h7p://www- sers.cselabs.mn.ed/classes/spring- 1/csci1/ Yo shold read

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

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

Bits, Bytes, and Integer

Bits, Bytes, and Integer 19.3 Compter Architectre Spring 1 Bits, Bytes, and Integers Nmber Representations Bits, Bytes, and Integer Representing information as bits Bit-level maniplations Integers Representation: nsigned and signed

More information

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

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

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

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

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

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

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

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

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

Today: Bits, Bytes, and Integers. Bits, Bytes, and Integers. For example, can count in binary. Everything is bits. Encoding Byte Values

Today: Bits, Bytes, and Integers. Bits, Bytes, and Integers. For example, can count in binary. Everything is bits. Encoding Byte Values Today: Bits, Bytes, and Integers Representing information as bits Bits, Bytes, and Integers CSci : Machine Architectre and Organization September th-9th, Yor instrctor: Stephen McCamant Bit-level maniplations

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

C Puzzles The course that gives CMU its Zip! Integer Arithmetic Operations Jan. 25, Unsigned Addition. Visualizing Integer Addition

C Puzzles The course that gives CMU its Zip! Integer Arithmetic Operations Jan. 25, Unsigned Addition. Visualizing Integer Addition 1513 The corse that gies CMU its Zip! Integer Arithmetic Operations Jan. 5, 1 Topics Basic operations Addition, negation, mltiplication Programming Implications Conseqences of oerflow Using shifts to perform

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

Byte Ordering. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Byte Ordering. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Byte Ordering Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Memory Model Physical memory DRAM chips can read/write 4, 8, 16 bits DRAM modules

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

Byte Ordering. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Byte Ordering. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Byte Ordering 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

Hardware: Logical View

Hardware: Logical View Hardware: Logical View CPU Memory Bus Disks Net USB Etc. 1 Hardware: Physical View USB I/O controller Storage connections CPU Memory 2 Hardware: 351 View (version 0) instructions? Memory CPU data CPU executes

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

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

Integer Encoding and Manipulation

Integer Encoding and Manipulation CSE 2421: Systems I Low-Level Programming and Computer Organization Integer Encoding and Manipulation Presentation D Study: Bryant Chapter 2.1 2.3 Gojko Babić 01-24-2018 Unsigned & Signed Integer Encoding

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

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

Bits, Bytes, and Integers

Bits, Bytes, and Integers Bits, Bytes, and Integers CENG331 - Computer Organization Instructors: Murat Manguoglu (Section 1) Adapted from slides of the textbook: http://csapp.cs.cmu.edu/ Hello World! What happens under the hood?

More information

CS429: Computer Organization and Architecture

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 11, 2017 at 08:58 CS429 Slideset 2: 1 Topics of this Slideset

More information

Topics of this Slideset. CS429: Computer Organization and Architecture. It s Bits All the Way Down. Why Binary? Why Not Decimal?

Topics of this Slideset. CS429: Computer Organization and Architecture. It s Bits All the Way Down. Why Binary? Why Not Decimal? Topics of this Slideset CS429: Computer Organization and Architecture There are 10 kinds of people in the world: those who understand binary, and those who don t! Dr. Bill Young Department of Computer

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

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

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

Data Representa+on in Memory

Data Representa+on in Memory Data Representa+on in Memory CSCI 2400 / ECE 3217: Computer Architecture Instructor: Prof. Jason FriAs Slides adapted from Bryant & O Hallaron s slides 1 Data Representa+on in Memory Basic memory organiza+on

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

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

Lecture 2: Number Representa2on

Lecture 2: Number Representa2on CSE 30: Computer Organization and Systems Programming Lecture 2: Number Representa2on Diba Mirza University of California, San Diego 1 Levels of Representation High Level Language Program (e.g., C) Compiler

More information

Outline. Integer representa+on and opera+ons Bit opera+ons Floa+ng point numbers. Reading Assignment:

Outline. Integer representa+on and opera+ons Bit opera+ons Floa+ng point numbers. Reading Assignment: Outline Integer representa+on and opera+ons Bit opera+ons Floa+ng point numbers Reading Assignment: Chapter 2 Integer & Float Number Representa+on related content (Sec+on 2.2, 2.3, 2.4) 1 Why we need to

More information

Outline. Integer representa+on and opera+ons Bit opera+ons Floa+ng point numbers. Reading Assignment:

Outline. Integer representa+on and opera+ons Bit opera+ons Floa+ng point numbers. Reading Assignment: Outline Integer representa+on and opera+ons Bit opera+ons Floa+ng point numbers Reading Assignment: Chapter 2 Integer & Float Number Representa+on related content (Sec+on 2.2, 2.3, 2.4) 1 Why we need to

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

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent? CSC 2400: Computer Systems Data Representa5on What kinds of data do we need to represent? - Numbers signed, unsigned, integers, floating point, complex, rational, irrational, - Text characters, strings,

More information

Roadmap. The Interface CSE351 Winter Frac3onal Binary Numbers. Today s Topics. Floa3ng- Point Numbers. What is ?

Roadmap. The Interface CSE351 Winter Frac3onal Binary Numbers. Today s Topics. Floa3ng- Point Numbers. What is ? The Hardware/So@ware Interface CSE351 Winter 013 Floa3ng- Point Numbers Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine

More information

Sign & Magnitude vs 2 s Complement ( Signed Integer Representa:ons)

Sign & Magnitude vs 2 s Complement ( Signed Integer Representa:ons) Sign & Magnitude vs 2 s Complement ( Signed Integer Representa:ons) Overview Unsigned Integers Representa:on (review) binary Signed Integers Representa:on sign & magnitude (S&M) 2 s complement (2 sc) arithme:c

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

Data Representa+on: Floa+ng Point Numbers

Data Representa+on: Floa+ng Point Numbers Data Representa+on: Floa+ng Point Numbers Csci 2021 - Machine Architecture and Organiza+on Professor Pen- Chung Yew With sides from Randy Bryant and Dave O Hallaron 1 Floa+ng Point Numbers Background:

More information

CSE351: Memory, Data, & Addressing I

CSE351: Memory, Data, & Addressing I CSE351: Memory, Data, & Addressing I CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis http://xkcd.com/138/

More information

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent? CSC 2400: Computer Systems Data Representa5on What kinds of data do we need to represent? - Numbers signed, unsigned, integers, floating point, complex, rational, irrational, - Text characters, strings,

More information

CSC 8400: Computer Systems. Represen3ng and Manipula3ng Informa3on. Background: Number Systems

CSC 8400: Computer Systems. Represen3ng and Manipula3ng Informa3on. Background: Number Systems CSC 8400: Computer Systems Represen3ng and Manipula3ng Informa3on Background: Number Systems 1 Analog vs. Digital System q Analog Signals - Value varies con1nuously q Digital Signals - Value limited to

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

Floa.ng Point : Introduc;on to Computer Systems 4 th Lecture, Sep. 10, Instructors: Randal E. Bryant and David R.

Floa.ng Point : Introduc;on to Computer Systems 4 th Lecture, Sep. 10, Instructors: Randal E. Bryant and David R. Floa.ng Point 15-213: Introduc;on to Computer Systems 4 th Lecture, Sep. 10, 2015 Instructors: Randal E. Bryant and David R. O Hallaron Today: Floa.ng Point Background: Frac;onal binary numbers IEEE floa;ng

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

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

Memory, Data, & Addressing II CSE 351 Spring

Memory, Data, & Addressing II CSE 351 Spring Memory, Data, & Addressing II CSE 351 Spring 2018 http://xkcd.com/138/ Review Questions 1) If the word size of a machine is 64-bits, which of the following is usually true? (pick all that apply) a) 64

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

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 1: Introduction Systems Programming and Computer

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

How a computer runs a program. Binary Representa8on and Opera8ons on Binary Data. Opera8ng System 9/17/13. You can view binary file contents

How a computer runs a program. Binary Representa8on and Opera8ons on Binary Data. Opera8ng System 9/17/13. You can view binary file contents Consider the following type defini8on and variable declara8ons: struct persont { struct persont p1; char name[32]; int age; struct persont people[40] float heart_rate; }; (1) What type is each of the following

More information

Main Memory Organization

Main Memory Organization Main Memory Organization Bit Smallest piece of memory Stands for binary digit Has values 0 (off) or 1 (on) Byte Is 8 consecu>ve bits Word Usually 4 consecu>ve bytes Has an address 8 bits 0 1 1 0 0 1 1

More information

CAPL Scripting Quickstart

CAPL Scripting Quickstart CAPL Scripting Qickstart CAPL (Commnication Access Programming Langage) For CANalyzer and CANoe V1.01 2015-12-03 Agenda Important information before getting started 3 Visal Seqencer (GUI based programming

More information

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18. with slides by Kip Irvine

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18. with slides by Kip Irvine Course overview Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18 with slides by Kip Irvine Logistics Meeting time: 9:10am-12:10pm, Monday Classroom: CSIE Room 102 Instructor: Yung-Yu

More information

Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #7. Warehouse Scale Computer

Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #7. Warehouse Scale Computer CS 61C: Great Ideas in Computer Architecture Everything is a Number Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13 9/19/13 Fall 2013 - - Lecture #7 1 New- School Machine Structures

More information

CS 261 Fall Binary Information (convert to hex) Mike Lam, Professor

CS 261 Fall Binary Information (convert to hex) Mike Lam, Professor CS 261 Fall 2018 Mike Lam, Professor 3735928559 (convert to hex) Binary Information Binary information Topics Base conversions (bin/dec/hex) Data sizes Byte ordering Character and program encodings Bitwise

More information

Floats are not Reals. BIL 220 Introduc6on to Systems Programming Spring Instructors: Aykut & Erkut Erdem

Floats are not Reals. BIL 220 Introduc6on to Systems Programming Spring Instructors: Aykut & Erkut Erdem Floats are not Reals BIL 220 Introduc6on to Systems Programming Spring 2012 Instructors: Aykut & Erkut Erdem Acknowledgement: The course slides are adapted from the slides prepared by R.E. Bryant, D.R.

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

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

Systems Programming and Computer Architecture ( )

Systems Programming and Computer Architecture ( ) (252-0061-00) Timothy Roscoe Herbstsemester 2013 Systems Group Department of Computer Science ETH Zürich 1 1: Introduction 252-0061-00, Herbstsemester 2013 Timothy Roscoe 2 This course covers in depth

More information

Data III & Integers I

Data III & Integers I Data III & Integers I CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Everyone has VM

More information

AGENDA Binary Operations CS 3330 Samira Khan

AGENDA Binary Operations CS 3330 Samira Khan AGENDA Binary Operations CS 3330 Logistics Review from last Lecture Samira Khan University of Virginia Jan 31, 2017 Binary Operations Logical Operations Bitwise Operations Examples 2 Feedbacks Quizzes

More information

CSE 351 Midterm - Winter 2015 Solutions

CSE 351 Midterm - Winter 2015 Solutions CSE 351 Midterm - Winter 2015 Solutions February 09, 2015 Please read through the entire examination first! We designed this exam so that it can be completed in 50 minutes and, hopefully, this estimate

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

Data III & Integers I

Data III & Integers I Data III & Integers I 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

More information

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion CS 61C: Great Ideas in Computer Architecture Lecture 2: Numbers & C Language Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Numbers wrap-up This is not on the exam! Break C Primer Administrivia,

More information

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz CS 61C: Great Ideas in Computer Architecture Lecture 2: Numbers & C Language Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Numbers wrap-up This is not on the exam! Break C Primer Administrivia,

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

CS107, Lecture 2 Bits and Bytes; Integer Representations

CS107, Lecture 2 Bits and Bytes; Integer Representations CS107, Lecture 2 Bits and Bytes; Integer Representations reading: Bryant & O Hallaron, Ch. 2.2-2.3 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons

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

CHW 261: Logic Design

CHW 261: Logic Design CHW 261: Logic Design Instructors: Prof. Hala Zayed Dr. Ahmed Shalaby http://www.bu.edu.eg/staff/halazayed14 http://bu.edu.eg/staff/ahmedshalaby14# Slide 1 Slide 2 Slide 3 Digital Fundamentals CHAPTER

More information