Few reminders and demos

Similar documents
Lecture 03 Bits, Bytes and Data Types

Bits, Bytes and Integers

Representing and Manipulating Integers Part I

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 2007/09/17. with slides by Kip Irvine

CS107, Lecture 2 Bits and Bytes; Integer Representations

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

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

Preview from Notesale.co.uk Page 6 of 52

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

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

Intro to Computers in Arabic!!!!! MAI ELSHEHALY

Arithmetic Operators. Portability: Printing Numbers

Bits, Bytes, and Integers

Types, Operators and Expressions

Lecture 5-6: Bits, Bytes, and Integers

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

Types, Operators and Expressions

Final Labs and Tutors

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #3: Of Integers and Endians (pt. 2)

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Fall 2018

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

Computer System and programming in C

Lecture 13 Bit Operations

data within a computer system are stored in one of 2 physical states (hence the use of binary digits)

Lecture 17 Bit Operations

Information Science 1

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

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

These are reserved words of the C language. For example int, float, if, else, for, while etc.

CS61B Lecture #14: Integers. Last modified: Wed Sep 27 15:44: CS61B: Lecture #14 1

Representing Integers

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

Module 1: Information Representation I -- Number Systems

Integer Representation

CS33 Project Gear Up. Data

The type of all data used in a C++ program must be specified

Today s Learning Objectives

Representation of Information

Topic Notes: Bits and Bytes and Numbers

Chapter 3 Basic Data Types. Lecture 3 1

PROGRAMMAZIONE I A.A. 2017/2018

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Electronic Data and Instructions

Binary Representations and Arithmetic

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

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

Representing and Manipulating Integers. Jo, Heeseung

The type of all data used in a C (or C++) program must be specified

Computer Systems CEN591(502) Fall 2011

MIPS Assembly: Practice Questions for Midterm 1 Saving to and Loading from Memory CS 64: Computer Organization and Design Logic Lecture #6

Binary Values. CSE 410 Lecture 02

ECE331: Hardware Organization and Design

T02 Tutorial Slides for Week 2

CS Programming In C

Survey. Motivation 29.5 / 40 class is required

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

Topic Notes: Bits and Bytes and Numbers

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

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

ECE2049-E17 Lecture 6 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

CS61B Lecture #14: Integers

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

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Programming in C++ 5. Integral data types

Computer Organization & Systems Exam I Example Questions

Programming in C Quick Start! Biostatistics 615 Lecture 4

Under the Hood: Data Representations, Memory and Bit Operations. Computer Science 104 Lecture 3

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Bits and Bytes January 13, 2005

ECE2049-E18 Lecture 6 Notes 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

COMP2121: Microprocessors and Interfacing. Number Systems

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

Before Class Install SDCC Instructions in Installing_SiLabs-SDCC- Drivers document. Solutions to Number Systems Worksheet. Announcements.

CSE351: Memory, Data, & Addressing I

In case you didn t get it (or you were too lazy to check)

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

CSE 30 Fall 2013 Final Exam

Binary Codes. Dr. Mudathir A. Fagiri

Midterm Exam Answers Instructor: Randy Shepherd CSCI-UA.0201 Spring 2017

Beginning C Programming for Engineers

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #9: Exam Review w/ Solutions

Experimental Methods I

l 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

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

ISA 563 : Fundamentals of Systems Programming

Computer Systems Programming. Practice Midterm. Name:

CPS 104 Computer Organization and Programming

Internal Data Representation

File Handling in C. EECS 2031 Fall October 27, 2014

UNIT- 3 Introduction to C++

large units some names for large numbers CIS 2107 Chapter 2 Notes Part 1

CIS 2107 Chapter 2 Notes Part 1. Representing and Manipulating Information

Variables and literals

Programming refresher and intro to C programming

Exercise: Inventing Language

AGENDA Binary Operations CS 3330 Samira Khan

Bits, Bytes, and Integers Part 2

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

Transcription:

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 negative numbers are represented Understand how computers add numbers Understand logical operations When there is a discrepancy between schedule and the date on the assignment go with assignment date. Few reminders and demos Always ask when in doubt Assignments are officially released within one week from the due date. Although you may be able to find a draft on download site, be sure to check back or talk to the course staff about changes Getting Started Install SSH on your computer (and FTP) Learn how to use Unix on Gates and Wean Clusters In order to be successful in this course You must be committed You must work hard You must seek help when needed Demos Create sub folders for program development Edit the program with emacs or equivalent Test, debug and submit to handin Salon -a new concept on social learning Make sure you have an account on Salon If not use code: 23456 to generate one or send email Join salons 15-123S11 Complete prior knowledge salon Vote for good responses Join your section Salon for rest of the semester activities Your course will have (alternatively) Salons and Quizzes Salons are collaborative Graded Quizzes are the good old take home quizzes 1

Lab Assignments in this course Requires you to log your activities. Labs must be completed on unix(no IDE s). Before any active session do the following > script session1.txt > your session commands > cntrld (saves the session) This is required for each lab (3 points) Also manually log your times Follow the formats carefully These files will be automatically processed Plan to attend help sessions this weekend You need to start right Start reading lab 1 you need more concepts from next week lectures How data is represented Data and Instructions Computers deal with two things Data int x = 10 Instructions add x,y store result, z 1001100111001 11001100111011 001100101010 001011001010 1010101010101 1001100111001 11001100111011 001100101010 001011001010 1010101010101 000011000111 Data as instructions and instructions as data Both Data and Instructions are represented the same way Representing Information Smallest Data unit is the bit Smallest addressable unit is the byte Each computer has a word size word is the amount of memory transferred between CPU and RAM Indicate the nominal size of integers and pointers Most common size is 32-bits 32-bit instructions, 32-bit integers Based on word size we can determine addressable space 2

Terminology 1 byte = 8 bits 1000 bytes = 1 kilo byte = 1 kb 1,000,000 bytes = 1 mega byte = 1 MB 1,000,000,000 bytes = 1 gigabyte = 1 GB 1,000,000,000,000 bytes = 1 terabyte = 1 TB 1000 PB s = 1 petabyte = 1 PB Then we have exabyte, zettabyte and yotabyte Question If a computer has 32-bit word size, what would be the range of virtual address space or max RAM? What if the computer is a 64-bit machine? Data Sizes Here are the typical 32-bit allocation for data types (in bytes) char (1), short int(2), int(4), long int(4) In compaq alpha long intis 8 char* (4), float (4), double (8) The exact size of data allocation depends on both compiler and machine Data value ranges <limits.h> library defines the range of values any data type can assume. Applications that are designed to be portable must use symbolic constants. Some examples INT_MIN Minimum value for a variable of type int. 2147483647 1 INT_MAX Maximum value for a variable of type int. 2147483647 UINT_MAX Maximum value for a variable of type unsigned int. 4294967295 (0xffffffff) LONG_MIN Minimum value for a variable of type long. 2147483647 1 LONG_MAX Maximum value for a variable of type long. Data Storage Classes auto Typical variables defined inside functions static Variables that retain values between function calls extern Declared within a function, but specifications given else where Register Data allocated to a register for quick access How integers are represented 3

Integer Representations Typical 32-bit machine uses 32-bit representation for signed and unsigned ints Range: Representation formats Decimal Binary Compaq alpha uses 64 bits for long int Range: Octal Hexadecimal Class/home work Convert 526 to binary, octal and hexadecimal /* prints the binary representation of a given int*/ void printbinary(int n) { Questions Suppose we write int x = 0x0F // to represent 15 How would you write The largest 32-bit positive integer The 6 th power of 2 A number that is divisible by 2 } Addressing and byte ordering Little Endian Least significant byte first (DEC, Intel) When byte ordering becomes an issue Communication of binary data over a network between different machines Big Endian Most significant byte first (IBM, Motorola, SUN) Code written for networking applications must then do their own conversions between machines Application programmers may not care about this ordering 4

Representing Negative numbers How about negative integers? The definition of x -x is the number y such that: x + y = 0 y is called the additive inverse Consider the 4-bit addition of signed numbers Class work Add the following using binary addition 00001011 and 11110101 How are signed and unsigned integers represented? Consider a n-bit integer representation of an unsigned integer Consider a n-bit integer representation of a signed integer Representing negative numbers using 2 s complement One s complement ~x Signed and unsigned numbers By default all constant values are signed const intx = 20, y =0x45 Two s complement 1 + ~x Can create an unsigned constant using const unsigned x = 0x123u (or U) 5

Logical Operations in C Performing logical operations Logical AND (&&) 0x75 && 0x 96 Logical OR ( ) Logical Not (! ) Bit Operations in C Bitwise AND ( &) ox75 & 0X96 Bitwise OR ( ) Bitwise negation (~) XOR ( ^ ) 6

Logic for adding bit by bit Si = (Ai ^ Bi) ^ Cin Cout = (Ai & Bi ) ((Ai ^ Bi) & Cin ) Counting number of 1 s in binary representation Let C(n) be the number of 1 s in n What is the relation between C(n) and C(n/2)? When n is even When n is odd Next: functions, arrays, String basics 7