Bits, Bytes, and Integers. Bits, Bytes, and Integers. The Decimal System and Bases. Everything is bits. Converting from Decimal to Binary
|
|
- Godwin Norris
- 6 years ago
- Views:
Transcription
1 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 of bits in varios ways Compters determine what to do (instrctions) and represent and maniplate nmbers, sets, strings, etc Why bits? Electronic Implementation Easy to store with bistable elements Reliably transmitted on noisy and inaccrate wires base 1 (decimal): digits -9 e.g., in the decimal system, 1 is the base, or radix any integer > 1 can be a base 1.1V.9V 1 base has two digits: and 1 bit binary digit V.V 3 Converting to Decimal Converting from Decimal to Binary Base eight (octal): digits -7 7 convert 193 to binary se a divisor of to obtain the following seqence of qotients and remainders Base 1 (hexadecimal): digits -9 and A-F 13C 1 Base (binary): digits, In general, radix r representations se the first r chars in { 9, A...Z} and have the form d n-1 d n- d 1 d. Smming d n-1 r n-1 + d n- r n- + + d r converts to base 1. dividend qotient remainder read remainders in reverse order
2 More Base Conversion Practice convert to base 1 by mltiplication of powers 11 5 ( ) 1 convert from base 1 by repeated division 3 1 ( ) converting base x to base y: convert base x to base 1 then convert base 1 to base y More Base Conversion Practice Convert from base ( ) 3 and check 13 1 ( ) 1 and check Another way to convert from decimal to base n for n n n 7 n n 5 n n 3 n n 1 n From LEFT TO RIGHT, ask how many and sbtract (19) 1 ( ) ( ) 1 7 Converting Between Hex and Binary Converting Between Hex and Binary chart of vales chart of vales decimal hex binary decimal hex binary A B C D E F 1111 to convert from binary to hex start at right of binary nmber convert each grop of digits into a hex vale e.g., convert to hex binary: hex: E C decimal hex binary decimal hex binary A B C D E F 1111 to convert from hex to binary replace each hex digit with its binary eqivalent e.g., convert A5 1 to binary hex: A 5 binary: Octal Every Base is Base 1 1 and 3 power # of bits per hex/octal digit Binary to Hex every bits 1 hex digit Octal base digits -7 Binary to Octal Every 3 bits 1 octal digit DEC OCT HEX BIN Notes A B C D E F In general, 1 X X
3 Other Binary Nmbers Base Nmber Representation Represent as Represent 1. 1 as [11] Represent X 1 as X 13 Encoding Byte Vales Byte bits Binary to Decimal: 1 to 551 Hexadecimal 1 to FF1 sefl for writing binary vales concisely write FA1D37B1 in C as xfa1d37b xfa1d37b A 1 11 B C 1 11 D E F Example Data Representations Today: C Data Type Typical 3-bit Typical -bit x- char short int long float doble long doble 1/1 Addition, negation, mltiplication, shifting pointer 15 1 Boolean Algebra General Boolean Algebras Developed by George Boole in 19th Centry Algebraic representation of logic Encode Tre as 1 and False as And A&B 1 when both A1 and B1 Or A B 1 when either A1 or B1 Operate on Bit Vectors Operations applied bitwise 1111 & ^ ~ All of the Properties of Boolean Algebra Apply Not ~A 1 when A Exclsive-Or (Xor) A^B 1 when either A1 or B1, bt not both
4 Example: Representing & Maniplating Sets Bit-Level Operations in C Representation Width w bit vector represents sbsets of {,, w 1} a j 1 if j A 1111 {, 3, 5, } {,,, } 7531 Operations & Intersection 11 {, } Union {,, 3,, 5, } ^ Symmetric difference 1111 {, 3,, 5 } ~ Complement 1111 { 1, 3, 5, 7 } 19 Operations &,, ~, ^ 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) ~x1 xbe ~ ~x xff ~ x9 & x55 x & x9 x55 x7d Contrast: Logic Operations in C Contrast: Logic Operations in C Contrast to Bit-level Operators &&,,! View as False Anything nonzero as Tre Always retrn or 1 Early termination Examples (char data type)!x1 x!x x1!!x1 x1 Contrast to Bit-level Operators &&,,! View as False Anything nonzero as Tre Always retrn or 1 Early termination Examples (char data type)!x1 x!x C x1 programming!!x1 x1 Watch ot for && vs. & (and vs. ) one of the more common oopsies in x9 && x55 x1 x9 x55 x1 p && *p (avoids nll pointer access) x9 && x55 x1 x9 x55 x1 p && *p (avoids nll pointer access) 1 Shift Operations Left Shift: x << y Shift bit-vector x left y positions Throw away extra bits on left Fill with s on right Right Shift: x >> y Shift bit-vector x right y positions Throw away extra bits on right Logical shift Fill with s on left Arithmetic shift Replicate most significant bit on left Undefined Behavior Shift amont < or word size Argment x 111 << 3 1 Log. >> 11 Arith. >> 11 Argment x 111 << 3 1 Log. >> 11 Arith. >> 1111 Addition, negation, mltiplication, shifting 3
5 Finite Precision the space to store integers in a compter is limited forced to deal with finite precision different machines se a varying nmber of bits for its word size, from to 5 bits nominal size of integer and pointer data 3 and bits are the crrent preferred sizes in general, we can store n different vales with n bits 1 bit: vales ( and 1) bits: vales (, 1, 1, 11) bits: 1 vales we ve seen..15, bt no negative vales Nmber of Vales Address space depends on word size word-size-in-#bits Is it big enogh? -bit high-end machines becoming more prevalent Portability isses insensitive to sizes of different data types # bytes # bits # of vales ( #bits) low high E+1.175E E+1 1.7E E E E E E E E E+3 5 Negative Vales so far, we ve seen the nmber of positive integers possible, bt no negative vales Encoding Integers BU(X) w 1 x i i i Two s Complement w BT(X) x w 1 w 1 x i i i common sense tells s to split the nmber of bit patterns into two grops of roghly the same size: one for positive vales and one for negative vales don t forget many ways to split these vales have been developed over the years two s complement is the most poplar nsigned only represents positive vales short int x 1513; short int y -1513; C short bytes long Decimal Hex Binary x B D y C Sign Bit For s complement, most significant bit indicates sign for nonnegative 1 for negative Sign Bit 7 Two-complement Encoding Example (Cont.) x 1513: y -1513: Weight Two s Complement Simple Conversion conversion sing a two-step process reverse the bits of the positive representation add 1 to the reslt e.g., reverse all bits add 1-9 only one representation for one more negative nmber than positive nmber Bryant and O Hallaron, Compter Systems: A Programmer s Sm Perspective, Third Edition
6 Two s Complement Alternate Conversion Nmeric Ranges alternate conversion sing a two-step process reading from right to left, copy all vales p to and inclding the first 1 reverse the remainder of the bits e.g., Vales UMin UMax w Vales for W 1 Two s Complement Vales TMin w 1 1 TMax w Other Vales Mins Decimal Hex Binary UMax 5535 FF FF TMax 377 7F FF TMin FF FF Vales for Different Word Sizes 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, Observations TMin TMax + 1 Asymmetric range UMax * TMax + 1 C Programming #inclde <limits.h> Declares constants, e.g., ULONG_MAX LONG_MAX LONG_MIN Vales platform specific & Signed Nmeric Vales X BU(X) BT(X) Eqivalence Same encodings for nonnegative vales Uniqeness Every bit pattern represents niqe integer vale Each representable integer has niqe bit encoding Can Invert Mappings UB(x) BU -1 (x) Bit pattern for nsigned integer TB(x) BT -1 (x) Bit pattern for two s comp integer 33 3 Mapping Between Signed & Addition, negation, mltiplication, shifting Two s Complement x x TU TB X BU Maintain Same Bit Pattern UT UB X BT Maintain Same Bit Pattern x Two s Complement x Mappings between nsigned and two s complement nmbers: Keep bit representations and reinterpret 35 3
7 Mapping Signed Mapping Signed Bits Signed Bits Signed TU UT / Relation between Signed & Conversion Visalized Two s Complement x TB TU BU X x s Comp. Ordering Inversion Negative Big Positive UMax UMax 1 w 1 x x Large negative weight becomes Large positive weight Maintain Same Bit Pattern s Complement Range TMax 1 TMin TMax + 1 TMax Range 39 Signed vs. in C Constants By defalt are considered to be signed integers if have U as sffix U, 99759U Casting Explicit casting between signed & nsigned same as UT and TU int tx, ty; nsigned x, y; tx (int) x; y (nsigned) ty; Implicit casting also occrs via assignments and procedre calls tx x; y ty; 1 Casting Srprises Expression Evalation If there is a mix of nsigned and signed in single expression, signed vales implicitly cast to nsigned Inclding comparison operations <, >,, <, > Examples for W 3: TMIN -,17,3,, TMAX,17,3,7 Constant 1 Constant Relation Evalation U nsigned -1-1 < signed -1-1 U > nsigned > signed 1737U < nsigned > signed (nsigned) > nsigned U < nsigned (int) 173U > signed 7
8 Smmary Casting Signed : Basic Rles Bit pattern is maintained Bt reinterpreted Can have nexpected effects: adding or sbtracting w Expression containing signed and nsigned int int is cast to nsigned!! Addition, negation, mltiplication, shifting 3 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 X w Sign Extension Example short int x 1513; int ix (int) x; short int y -1513; int iy (int) y; Decimal Hex Binary x B D ix B D y C iy FF FF C Converting from smaller to larger integer data type C atomatically performs sign extension k 5 Smmary: Expanding, Trncating: Basic Rles Expanding (e.g., short int to int) : zeros added Signed: sign extension Both yield expected reslt Trncating (e.g., nsigned to nsigned short) /signed: bits are trncated Reslt reinterpreted : mod operation Signed: similar to mod For small nmbers yields expected behavior Addition, negation, mltiplication, shifting 7
9 Addition Operands: w bits Tre Sm: w+1 bits Standard Addition Fnction Ignores carry otpt Implements Modlar Arithmetic s UAdd w (, v) + v mod w + v + v Discard Carry: w bits UAdd w (, v) Visalizing (Mathematical) Integer Addition Integer Addition -bit integers, v Compte tre sm Add (, v) Vales increase linearly with and v Forms planar srface Add (, v) Integer Addition v Visalizing Addition Two s Complement Addition Wraps Arond If tre sm w At most once Overflow UAdd (, v) Operands: w bits Tre Sm: w+1 bits + v + v Discard Carry: w bits TAdd w (, v) Tre Sm w+1 w Overflow Modlar Sm v TAdd and UAdd have Identical Bit-Level Behavior Signed vs. nsigned addition in C: int s, t,, v; s (int) ((nsigned) + (nsigned) v); t + v Will give s t 51 5 TAdd Overflow Visalizing s Complement Addition Fnctionality Tre sm reqires w+1 bits Drop off MSB Treat remaining bits as s comp. integer Tre Sm w 1 PosOver w 1 1 w 1 w NegOver TAdd Reslt Vales -bit two s comp. Range from - to +7 Wraps Arond If sm w 1 Becomes negative At most once If sm < w 1 Becomes positive At most once NegOver TAdd (, v) v PosOver
10 Mltiplication Goal: Compting Prodct of w-bit nmbers x, y Either signed or nsigned Bt, exact reslts can be bigger than w bits : p to w bits Reslt range: x * y ( w 1) w w Two s complement min (negative): Up to w-1 bits Reslt range: x * y ( w 1 )*( w 1 1) w + w 1 Two s complement max (positive): Up to w bits, bt only for (TMin w ) Reslt range: x * y ( w 1 ) w So, maintaining exact reslts wold need to keep expanding word size with each prodct compted is done in software, if needed e.g., by arbitrary precision arithmetic packages Mltiplication in C Operands: w bits Tre Prodct: *w bits v Discard w bits: w bits Standard Mltiplication Fnction Ignores high order w bits Implements Modlar Arithmetic UMlt w (, v) v mod w * v UMlt w (, v) 55 5 Signed Mltiplication in C Power-of- Mltiply with Shift Operands: w bits Tre Prodct: *w bits v Discard w bits: w bits Standard Mltiplication Fnction Ignores high order w bits Some of which are different for signed vs. nsigned mltiplication Lower bits are the same * v TMlt w (, v) Operation << k gives * k Both signed and nsigned Operands: w bits Tre Prodct: w+k bits k Discard k bits: w bits UMlt w (, k ) TMlt w (, k ) Examples << 3 * ( << 5) ( << 3) * Most machines shift and add faster than mltiply Compiler generates this code atomatically * k k Power-of- Divide with Shift Qotient of by Power of >> k gives / k Uses logical shift k Binary Point Operands: / k 1 Division: / k. Reslt: / k Division Compted Hex Binary x B D x >> D B x >> B x >> B Addition, negation, mltiplication, shifting 59 1
11 Arithmetic: Basic Rles Why Shold I Use? Addition: /signed: Normal addition followed by trncate, same operation on bit level : addition mod w Mathematical addition + possible sbtraction of w Signed: modified addition mod w (reslt in proper range) Mathematical addition + possible addition or sbtraction of w Mltiplication: /signed: Normal mltiplication followed by trncate, same operation on bit level : mltiplication mod w Signed: modified mltiplication mod w (reslt in proper range) Don t se withot nderstanding implications Easy to make mistakes nsigned i; for (i cnt-; i > ; i--) a[i] + a[i+1]; Can be very sbtle #define DELTA sizeof(int) int i; for (i CNT; i-delta > ; i- DELTA)... 1 Conting Down with Why Shold I Use? (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 addition will behave like modlar arithmetic 1 UMax Even better 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 <? 3 Do Use When Performing Modlar Arithmetic Mltiprecision arithmetic Do Use When Using Bits to Represent Sets Logical right shift, no sign extension Byte-Oriented Memory Organization Addition, negation, mltiplication, shifting 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 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 5 11
12 Machine Words Any given compter has a Word Size Nominal size of integer-valed data and of addresses Until recently, most machines sed 3 bits ( bytes) as word size Limits addresses to GB ( 3 bytes) Increasingly, machines have -bit word size Potentially, cold have 1 EB (exabytes) of addressable memory That s 1. X 1 1 Machines still spport mltiple data formats Fractions or mltiples of word size Always integral nmber of bytes 7 Word-Oriented Memory Organization Addresses Specify Byte Locations Address of first byte in word Addresses of sccessive words differ by (3-bit) or (-bit) 3-bit Words Addr?? Addr?? Addr?? Addr 1?? -bit Words Addr?? Addr?? Bytes Addr Example Data Representations Byte Ordering C Data Type Typical 3-bit Typical -bit x- char short int long float doble So, how are the bytes within a mlti-byte word ordered in memory? Conventions Big Endian: Sn, PPC Mac, Internet Least significant byte has highest address Little Endian: x, ARM processors rnning Android, ios, and Windows Least significant byte has lowest address long doble 1/1 pointer 9 7 Byte Ordering Example Example Variable x has -byte vale of x1357 Address given by &x is x1 Big Endian Little Endian x1 x11 x1 x x1 x11 x1 x Representing Integers int A 1513; IA3, x- D 3B Sn 3B D int B -1513; IA3, x- 93 C FF FF Sn FF FF C 93 Decimal: 1513 Binary: Hex: 3 B D long int C 1513; IA3 D 3B x- D 3B Two s complement representation Sn 3B D
13 Examining Data Representations show_bytes Exection Example Code to Print Byte Representation of Data Casting pointer to nsigned char * allows treatment as a byte array typedef nsigned char *pointer; int a 1513; printf("int a 1513;\n"); show_bytes((pointer) &a, sizeof(int)); 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 Reslt (Linx x-): int a 1513; x7fffb7f71dbc d x7fffb7f71dbd 3b x7fffb7f71dbe x7fffb7f71dbf 73 7 Representing Pointers Representing Strings int B -1513; int *P &B; Sn EF FF FB C IA3 AC F5 FF x- 3C 1B FE FD 7F char S[] "113"; Strings in C Represented by array of characters Each character encoded in ASCII format IA3 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 Final character Compatibility Byte ordering not an isse Different compilers & machines assign different locations to objects Even get different reslts each time rn program
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 informationPage # 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 informationBits, 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 informationBits, 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 informationBits, Bytes, and Integers. Data Representa+on: Base- 2 number representa+on. Binary Representa+ons. Encoding Byte Values. Example Data Representa+ons
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,
More informationCarnegie 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 informationC 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 informationToday: 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 informationComputer 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 informationPage 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 informationFoundations 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 informationCS140 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 informationBits, 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 informationBits, 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 informationLecture 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 informationIntegers. 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 informationSystems 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 informationIntegers 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 informationIntegers. 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 informationSystems 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 informationICS 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 informationBits, 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 informationCsci 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 informationBITS, 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 informationJin-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 informationBits, 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 informationC 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 informationCS 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 informationBits 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 informationArithmetic 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 informationPage 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 informationTopics 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 informationCS429: 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 informationBits 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 informationRepresenta7on 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 informationRepresenting 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 informationComputer 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 informationArithmetic 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 informationCS 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 informationInteger 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 informationBits 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 informationWhy 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 informationRepresenting 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 informationWhy 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 informationInteger 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 informationHardware: 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 informationCS 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 informationCS 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 informationManipulating 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 informationRepresenting 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 informationBut 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 informationCSCI2467: 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 informationBits, 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 informationCS429: 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 informationTopics 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 informationRepresenting 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 informationComputer 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 informationCAPL 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 informationIntegers 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 informationIntegers 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 informationByte 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 informationIntegers 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 informationByte 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 informationMemory, 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 informationBitwise 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 informationREMEMBER 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 informationPOWER-OF-2 BOUNDARIES
Warren.3.fm Page 5 Monday, Jne 17, 5:6 PM CHAPTER 3 POWER-OF- BOUNDARIES 3 1 Ronding Up/Down to a Mltiple of a Known Power of Ronding an nsigned integer down to, for eample, the net smaller mltiple of
More informationSimple 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 informationCS107, 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 informationDr Paolo Guagliardo. Fall 2018
The NULL vale Dr Paolo Gagliardo dbs-lectrer@ed.ac.k Fall 2018 NULL: all-prpose marker to represent incomplete information Main sorce of problems and inconsistencies... this topic cannot be described in
More informationCS107, 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 informationArithmetic 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 informationCOMP2611: 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 informationReview. How to represent real numbers
PCWrite PC IorD Review ALUSrcA emread Address Write data emory emwrite em Data IRWrite [3-26] [25-2] [2-6] [5-] [5-] RegDst Read register Read register 2 Write register Write data RegWrite Read data Read
More informationChapter 7. Basic Types
Chapter 7 Basic Types Dr. D. J. Jackson Lecture 7-1 Basic Types C s basic (built-in) types: Integer types, including long integers, short integers, and unsigned integers Floating types (float, double,
More informationCOMP2121: Microprocessors and Interfacing. Number Systems
COMP2121: Microprocessors and Interfacing Number Systems http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 2, 2017 1 1 Overview Positional notation Decimal, hexadecimal, octal and binary Converting
More informationCS 107 Lecture 3: Integer Representations
CS 107 Lecture 3: Integer Representations Monday, January 15, 2018 Computer Systems Winter 2018 Stanford University Computer Science Department Reading: Reader: Bits and Bytes, Textbook: Chapter 2.2 Lecturers:
More informationTopic Notes: Bits and Bytes and Numbers
Computer Science 220 Assembly Language & Comp Architecture Siena College Fall 2010 Topic Notes: Bits and Bytes and Numbers Binary Basics At least some of this will be review, but we will go over it for
More informationCourse 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 informationArithmetic 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 informationCS 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 informationBasic 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 informationThe type of all data used in a C (or C++) program must be specified
The type of all data used in a C (or C++) program must be specified A data type is a description of the data being represented That is, a set of possible values and a set of operations on those values
More informationReview. A single-cycle MIPS processor
Review If three instrctions have opcodes, 7 and 5 are they all of the same type? If we were to add an instrction to IPS of the form OD $t, $t2, $t3, which performs $t = $t2 OD $t3, what wold be its opcode?
More informationCS 153 Design of Operating Systems
CS 153 Design of Operating Systems Spring 18 Lectre 3: OS model and Architectral Spport Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Last time/today
More informationComputer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers
Computer Science 324 Computer Architecture Mount Holyoke College Fall 2007 Topic Notes: Bits and Bytes and Numbers Number Systems Much of this is review, given the 221 prerequisite Question: how high can
More informationThe type of all data used in a C++ program must be specified
The type of all data used in a C++ program must be specified A data type is a description of the data being represented That is, a set of possible values and a set of operations on those values There are
More informationBinary Representations and Arithmetic
Binary Representations and Arithmetic 9--26 Common number systems. Base : decimal Base 2: binary Base 6: hexadecimal (memory addresses) Base 8: octal (obsolete computer systems) Base 64 (email attachments,
More informationInteger 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 informationCHW 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 informationCourse Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation
Course Schedule CS 221 Computer Architecture Week 3: Information Representation (2) Fall 2001 W1 Sep 11- Sep 14 Introduction W2 Sep 18- Sep 21 Information Representation (1) (Chapter 3) W3 Sep 25- Sep
More informationl l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers
198:211 Computer Architecture Topics: Lecture 8 (W5) Fall 2012 Data representation 2.1 and 2.2 of the book Floating point 2.4 of the book Computer Architecture What do computers do? Manipulate stored information
More informationMemory, Data, & Addressing II
Memory, Data, & Addressing II CSE 351 Autumn 2018 Instructor: Justin Hsia Teaching Assistants: Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson
More informationThe extra single-cycle adders
lticycle Datapath As an added bons, we can eliminate some of the etra hardware from the single-cycle path. We will restrict orselves to sing each fnctional nit once per cycle, jst like before. Bt since
More informationData 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 informationInteger 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 informationIntroduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C
Final Review CS304 Introduction to C Why C? Difference between Python and C C compiler stages Basic syntax in C Pointers What is a pointer? declaration, &, dereference... Pointer & dynamic memory allocation
More informationSIGNED 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 informationCS107, 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 informationThe multicycle datapath. Lecture 10 (Wed 10/15/2008) Finite-state machine for the control unit. Implementing the FSM
Lectre (Wed /5/28) Lab # Hardware De Fri Oct 7 HW #2 IPS programming, de Wed Oct 22 idterm Fri Oct 2 IorD The mlticycle path SrcA Today s objectives: icroprogramming Etending the mlti-cycle path lti-cycle
More information