Representing Integers
|
|
- Annabel Freeman
- 5 years ago
- Views:
Transcription
1 Representing Integers Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong
2 Unsigned Integers Encoding unsigned integers B = [ bw- 1, bw-2,..., b0 ] x = D( B) = w - 1 åb i i= 0 2 i D(x) = = = 2003 What is the range for unsigned values with w bits? SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 2 2
3 Signed Integers (1) Encoding positive numbers Same as unsigned numbers Encoding negative numbers Sign-magnitude representation Ones complement representation Two s complement representation SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 3 3
4 Signed Integers (2) Sign-magnitude representation b w-1 b w-2 b 1 b 0 Sign bit S w b æ - = - çå w- B) ( 1) è i= ( 1 Magnitude 2 Two zeros [000 00], [ ] Used for floating-point numbers 2 0 b i i ö ø SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 4 4
5 Signed Integers (3) Ones complement representation b w-1 b w-2 b 1 b 0 Sign bit w æ - 2 w-1 O( B) = -b - + çå w -1(2 1) bi 2 è i= 0 Easy to find n Two zeros [ ], [ ] No longer used i ö ø SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 5 5
6 Signed Integers (4) Two s complement representation b w-1 b w-2 b 1 b 0 Sign bit 1101 w æ - 2 w-1 ö = - + çå i O( B) b w -1 2 bi è i= 0 ø 1011 Unique zero Easy for hardware leading 0 0 leading 1 < 0 Used by almost all modern machines SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 6 6
7 Signed Integers (5) Two s complement representation (cont d) Following holds for two s complement ~ x + 1 == x Complement Observation: ~ x + x == == 1 Increment ~ x + x == 1 ~ x + x + ( x + 1) == 1 + ( x + 1) ~ x + 1 == x SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 7 7
8 Numeric Ranges (1) Unsigned values UMin = 0 [000 00] UMax = 2 w 1 [111 11] Two s complement values TMin = 2 w-1 [100 00] TMax = 2 w-1 1 [011 11] Decimal Hex Binary Values for w = 16 UMax FF FF TMax F FF TMin FF FF SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 8 8
9 Numeric Ranges (2) Values for different word sizes w = 8 w = 16 w = 32 w = 64 UMax ,535 4,294,967,295 18,446,744,073,709,551,615 TMax ,767 2,147,483,647 9,223,372,036,854,775,807 TMin ,768-2,147,483,648-9,223,372,036,854,775,808 Observations TMin = TMax + 1 (Asymmetric range) UMax = 2 * TMax + 1 In C programming #include <limits.h> INT_MIN, INT_MAX, LONG_MIN, LONG_MAX, UINT_MAX, Values platform-specific SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 9 9
10 Type Conversion (1) Unsigned: w bits à w+k bits Zero extension: just fill k bits with 0 s unsigned short x = 2003; unsigned ix = (unsigned) x; x w = ix k = 16 w = 16 SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 1010
11 Type Conversion (2) Signed: w bits à w+k bits Given w-bit signed integer x Convert it to w+k-bit integer with same value Sign extension Make k copies of sign bit X Sign bit w X k w SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 1111
12 Type Conversion (3) Sign extension example Converting from smaller to larger integer type C automatically performs sign extension short int x = 2003; int ix = (int) x; short int y = -2003; int iy = (int) y; Decimal Hex Binary x D ix D y F8 2D iy FF FF F8 2D SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 1212
13 Type Conversion (4) Unsigned & Signed: w+k bits à w bits Just truncate it to lower w bits Equivalent to computing x mod 2 w unsigned int x = 0xcafebabe; unsigned short ix = (unsigned short) x; int y = 0x2003beef; short iy = (short) y; Decimal Hex Binary x CA FE BA BE ix BA BE y BE EF iy BE EF SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 1313
14 Type Conversion (5) Unsigned à Signed The same bit pattern is interpreted as a signed number U 2 w 2 w 1 0 w-1 2Tw ( x) = í w w-1 Unsigned ì x, îx - 2 Two s complement +2 w 1 0, x x 2 w 1 < ³ 2 2 unsigned short x = 2003; short ix = (short) x; unsigned short y = 0xbabe; short iy = (short) y; Decimal Hex Binary x D ix D y BA BE iy BA BE SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 1414
15 Type Conversion (6) Signed à Unsigned Ordering inversion Negative à Big positive T 2U w Two s complement +2 w 1 ( x) = w ì x + 2, x < í î x, x ³ 2 w 2 w short x = 2003; unsigned short ix = (unsigned short) x; short y = -2003; unsigned short iy = (unsigned short) y; Decimal Hex Binary x D w 1 0 Unsigned ix D y F8 2D iy F8 2D SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 1515
16 Type Casting in C Constants By default, considered to be signed integers Unsigned if they have U or u as suffix e.g. 0U, 12345U, 0x1A2Bu Type casting Explicit casting Implicit casting via Assignments Procedure calls int tx, ty; unsigned ux, uy; tx = (int) ux; uy= (unsigned) ty; int f(unsigned); tx = ux; f(ty); SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 1616
17 Expression Evaluation in C If mix unsigned and signed in single expression, signed values implicitly cast to unsigned Including comparison operations <, >, ==, <=, >= Expression Type Evaluation 0 == 0U -1 < 0-1 < 0U -1 > -2 (unsigned) -1 > > U > > (int) U unsigned signed True True unsigned? signed? unsigned? signed? unsigned? signed? SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 1717
18 Example 1 #include <stdio.h> int main () { unsigned i; for (i = 10; i >= 0; i--) printf ( %u\n, i); } SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 1818
19 Example 2 #include <stdio.h> #define DELTA sizeof(int) int main () { int i; for (i = 10; i DELTA >= 0; i -= DELTA) printf ( %d\n, i); } SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 1919
20 Example 3 #include <string.h> int strlonger (char *s, char *t) { return (strlen(s) strlen(t)) > 0; } SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 2020
21 Example 4 int sum_array (int a[], unsigned len) { int i; int result = 0; for (i = 0; i <= len 1; i++) result += a[i]; } return result; SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 2121
22 Example 5 #include <stdio.h> int main () { unsigned char c; } while ((c = getchar())!= EOF) putchar (c); SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu) 2222
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 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 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 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 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 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 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 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 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 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 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 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 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 informationBits, 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 informationComputer Systems Programming. Practice Midterm. Name:
Computer Systems Programming Practice Midterm Name: 1. (4 pts) (K&R Ch 1-4) What is the output of the following C code? main() { int i = 6; int j = -35; printf( %d %d\n,i++, ++j); i = i >
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 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 informationData Type Fall 2014 Jinkyu Jeong
Data Type Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 Syntax Rules Recap. keywords break double if sizeof void case else int static... Identifiers not#me scanf 123th printf _id so_am_i gedd007 Constants
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 informationRepresenting and Manipulating Floating Points
Representing and Manipulating Floating Points Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE23: Introduction to Computer Systems, Spring 218,
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 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 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 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 information1.1. Unit 1. Integer Representation
1.1 Unit 1 Integer Representation 1.2 Skills & Outcomes You should know and be able to apply the following skills with confidence Convert an unsigned binary number to and from decimal Understand the finite
More informationBits, 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 informationFile Handling in C. EECS 2031 Fall October 27, 2014
File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically
More informationData Types. Data Types. Integer Types. Signed Integers
Data Types Data Types Dr. TGI Fernando 1 2 The fundamental building blocks of any programming language. What is a data type? A data type is a set of values and a set of operations define on these values.
More 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 informationInternal representation. Bitwise operators
Computer Programming Internal representation. Bitwise operators Marius Minea marius@cs.upt.ro 24 October 2016 Ideal math and C are not the same! In mathematics: integers Z and reals R have unbounded values
More informationInternal representation. Bitwise operators
Computer Programming Internal representation. Bitwise operators Marius Minea marius@cs.upt.ro 23 October 2017 Ideal math and C are not the same! In mathematics: integers Z and reals R have unbounded values
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 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 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 informationTHE FUNDAMENTAL DATA TYPES
THE FUNDAMENTAL DATA TYPES Declarations, Expressions, and Assignments Variables and constants are the objects that a prog. manipulates. All variables must be declared before they can be used. #include
More informationThese are reserved words of the C language. For example int, float, if, else, for, while etc.
Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.
More informationInternal representation. Bitwise operators
Computer Programming Internal representation. Bitwise operators Marius Minea marius@cs.upt.ro 26 October 2015 Ideal math and C are not the same! In mathematics: integers Z and reals R have unbounded values
More informationFew reminders and demos
15-123 Effective Programming in C and Unix Learning Objectives At the end of this lecture, you should be able to Understand how data is represented Understand how integers are represented Understand how
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 informationTypes, Operators and Expressions
Types, Operators and Expressions CSE 2031 Fall 2011 9/11/2011 5:24 PM 1 Variable Names (2.1) Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a
More informationComputer System and programming in C
1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign
More informationData 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 informationTypes, Operators and Expressions
Types, Operators and Expressions EECS 2031 18 September 2017 1 Variable Names (2.1) l Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a keyword.
More informationData 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 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 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 information5.Coding for 64-Bit Programs
Chapter 5 5.Coding for 64-Bit Programs This chapter provides information about ways to write/update your code so that you can take advantage of the Silicon Graphics implementation of the IRIX 64-bit operating
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 informationThe Design of C: A Rational Reconstruction"
The Design of C: A Rational Reconstruction 1 Goals of this Lecture Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C and thereby
More informationComputer Organization & Systems Exam I Example Questions
Computer Organization & Systems Exam I Example Questions 1. Pointer Question. Write a function char *circle(char *str) that receives a character pointer (which points to an array that is in standard C
More informationDigital Systems. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University
Digital Systems 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 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 informationNumber Representation
Number Representation Prof. Harry H. Porter Portland State University Harry H. Porter, 2014 1 Decimal Number Representation Example: 4037 = 4000 + 30 + 7 =... + 0 10000 + 4 1000 + 0 100 + 3 10 + 7 1 =...
More informationDeclaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.
Declaration Fundamental Data Types All variables must be declared before being used. Tells compiler to set aside an appropriate amount of space in memory to hold a value. Enables the compiler to perform
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 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 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 informationWorld Inside a Computer is Binary
C Programming 1 Representation of int data World Inside a Computer is Binary C Programming 2 Decimal Number System Basic symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Radix-10 positional number system. The radix
More informationProgramming Language A
Programming Language A Takako Nemoto (JAIST) 26 November Takako Nemoto (JAIST) 26 November 1 / 12 Type char char is a datatype for characters. char express integers in certain region. For each ASCII character,
More informationCIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm Solutions
Fall 2011 Name: Page Points Score 1 7 2 10 3 8 4 13 6 17 7 4 8 16 9 15 10 10 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc. For each of the
More informationCS367 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 informationNumber Systems, Scalar Types, and Input and Output
Number Systems, Scalar Types, and Input and Output Outline: Binary, Octal, Hexadecimal, and Decimal Numbers Character Set Comments Declaration Data Types and Constants Integral Data Types Floating-Point
More informationThe Design of C: A Rational Reconstruction
The Design of C: A Rational Reconstruction 1 Goals of this Lecture Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C and thereby
More information1.3b Type Conversion
1.3b Type Conversion Type Conversion When we write expressions involved data that involves two different data types, such as multiplying an integer and floating point number, we need to perform a type
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 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 informationThe Design of C: A Rational Reconstruction" Jennifer Rexford!
The Design of C: A Rational Reconstruction" Jennifer Rexford! 1 Goals of this Lecture"" Number systems! Binary numbers! Finite precision! Binary arithmetic! Logical operators! Design rationale for C! Decisions
More informationint main() { return 0; }
int main() { return 0; % gcc x.c %./a.out % gcc -o x x.c %./x int main() { return 1; 0 % gcc -Wall -o x x.c %./x int main() { printf("hi\n"); return 0; \n #include int main() { printf("hi\n");
More informationCS & IT Conversions. Magnitude 10,000 1,
CS & IT Conversions There are several number systems that you will use when working with computers. These include decimal, binary, octal, and hexadecimal. Knowing how to convert between these number systems
More informationCS356: Discussion #3 Floating-Point Operations. Marco Paolieri
CS356: Discussion #3 Floating-Point Operations Marco Paolieri (paolieri@usc.edu) Today s Agenda More Integer operations exercise Floating-Point operations exercise for Lab 2 Data Lab 2: What to implement
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 informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationCYSE 411/AIT681 Secure Software Engineering Topic #10. Secure Coding: Integer Security
CYSE 411/AIT681 Secure Software Engineering Topic #10. Secure Coding: Integer Security Instructor: Dr. Kun Sun 1 This lecture: [Seacord]: Chapter 5 Readings 2 Secure Coding String management Pointer Subterfuge
More information2/9/18. Readings. CYSE 411/AIT681 Secure Software Engineering. Introductory Example. Secure Coding. Vulnerability. Introductory Example.
This lecture: [Seacord]: Chapter 5 Readings CYSE 411/AIT681 Secure Software Engineering Topic #10. Secure Coding: Integer Security Instructor: Dr. Kun Sun 1 2 String management Pointer Subterfuge Secure
More information2/9/18. CYSE 411/AIT681 Secure Software Engineering. Readings. Secure Coding. This lecture: String management Pointer Subterfuge
CYSE 411/AIT681 Secure Software Engineering Topic #10. Secure Coding: Integer Security Instructor: Dr. Kun Sun 1 This lecture: [Seacord]: Chapter 5 Readings 2 String management Pointer Subterfuge Secure
More informationCS:APP Web Aside DATA:TMIN: Writing TMin in C
CS:APP Web Aside DATA:TMIN: Writing TMin in C Randal E. Bryant David R. O Hallaron December 29, 2014 Notice The material in this document is supplementary material to the book Computer Systems, A Programmer
More informationDay05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14
Day05 A Young W. Lim 2017-10-07 Sat Young W. Lim Day05 A 2017-10-07 Sat 1 / 14 Outline 1 Based on 2 Structured Programming (2) Conditions and Loops Conditional Statements Loop Statements Type Cast Young
More informationCIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm
Fall 2011 Name: Page Points Score 1 5 2 10 3 10 4 7 5 8 6 15 7 4 8 7 9 16 10 18 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc. For each of
More informationProgramming & Data Structure: CS Section - 1/A DO NOT POWER ON THE MACHINE
DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 1 Tutorial Programming & Data Structure: CS 11001 Section - 1/A DO NOT POWER ON THE MACHINE Department of Computer Science and Engineering
More information