CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 645-4739

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 1.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double,
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double,
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
Signed Numbers Up till now we've been concentrating on unsigned numbers. In real life we have to represent signed numbers ( like: -12, -45, 78). The difference.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Data Representation ICS 233
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
Binary numbers and arithmetic. ADDITION Addition (decimal)
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
Simple Data Type Representation and conversion of numbers
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
Chapter 1 Data Storage(3) Yonsei University 1 st Semester, 2015 Sanghyun Park.
Computer Architecture
Number Systems Spring Semester 2013Programming and Data Structure1.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
Number Representation. 10/12/2015CDA31002 Conversion between Representations Now we can represent a quantity in different number representations How can.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Number Representation
By Jariya Phongsai A two's-complement system is a system in which negative numbers are represented by the two's complement of the absolute value; this.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.6 Instructor: Lin Chen Sept 2013.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Information Representation: Negative Integer Representation.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
Lecture 4: Representing Negative Numbers CS 2011 Spring 2016, Dr. Rozier.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
Data Representation COE 308 Computer Architecture
Cosc 2150: Computer Organization
Backgrounder: Binary Math
Programming and Data Structure
Data Representation ICS 233
Data Representation.
Number Representation
Numbers in a Computer Unsigned integers Signed magnitude
Data Structures Mohammed Thajeel To the second year students
Data Representation COE 301 Computer Organization
Negative Integer Representation
1 The Hardware/Software Interface CSE351 Spring 2011 Module 3: Integers Monday, April 4, 2011.
Unit 18: Computational Thinking
Data Representation ICS 233
Names of variables, functions, classes
OBJECTIVES After reading this chapter, the reader should be able to :
Data Representation COE 308 Computer Architecture
Presentation transcript:

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall

Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double, float Values of the primitive types are not objects –no properties –no capabilities

boolean values: true, false operations: &&“and” ||“or” !“not”

int values: 0, 1, -1, 2, -2, … maximum int: = +2 (32-1) -1 minimum int: = -2 (32-1) operations: + - * / % 5+2 = 7+: (int,int)  int 5-2 = 3 -: (int,int)  int 5*2 = 10 *: (int,int)  int 5/2 = 2 (quotient) /: (int,int)  int 5%2 = 1 (remainder)%: (int,int)  int

integral types’ representations representation used differs according to whether type is signed (byte, short, int, long) or unsigned (char): –signed integral values are represented using “two’s complement” representation –unsigned integral values are represented using “binary” representation size of representation differs according to type: –byte is 1 byte wide (1 byte = 8 bits) –short is 2 bytes wide –int is 4 bytes wide –long is 8 bytes wide main point: values of different types have different representations – you can’t “mix and match”!

types of operators for type int Notice that all of these operators take two int arguments, and produce an int result. There is hardware circuitry to perform these operations.

Two’s complement fixed-width encoding limited range of values encodes both negative and non-negative values familiar properties hold –unique representation of zero ( 0 = -0 ) –x + 0 = 0 + x = x –x = - ( -x ) –x + (-x) = 0 –x - y = x + ( -y ) last property lets us use addition circuitry to perform subtraction

Bit pattern interpretation half of bit patterns (those with a zero in the leftmost bit) are for non- negative values, and are interpreted just as base 2 (binary) numbers are the assignment of values to the remaining bit patterns is done as described on the following slides

-x To find representation of -x given the representation of x: 1.find the one’s complement of x do this by flipping all the bits in the representation (1 becomes 0, 0 becomes 1) 2.find the two’s complement of the result do this by adding one to the one’s complement, ignoring any overflow carry

Example Using a 4-bit wide representation, find the representation of -3: –representation: 0011 –one’s complement: 1100 –two’s complement: 1101 Representation of -3 is 1101 Exercise: verify that the desirable properties hold!

Extra pattern? since -0 = 0, there is one leftover “negative” bit string let that represent a negative number, -8 in the case of a 4-bit wide representation in general, range of values for a k-bit wide two’s complement representation is from -2 (k-1) to +2 (k-1) -1 for 4-bit wide representation: -8 to +7

Rollover What happens when you add 1 to 7 in the 4-bit wide scheme? = 1000 The answer is -8 (!) Adding one to the largest magnitude positive number yields the largest magnitude negative number.

Extra negative number The negative of the largest magnitude negative number is itself. In the 4-bit wide scheme, -(-8) is -8.

Understand the representation! It is important that you understand the limitations of working with fixed-width representations.

‘+’ is overloaded ‘+’ is just a name ‘+’ has different interpretations –String concatenation –integer addition addition of two’s complement numbers –floating point addition addition of IEEE754 numbers

type of ‘+’ In the following expression, what is the type of ‘+’? 5 + 2

mappings an operator / function maps from a domain set to a range set: DOMAINRANGE

‘+’ as int addition range is int domain is pairs of int ‘+’ has type int x int  int DOMAIN int X int RANGEint

relational operators We can form expressions like: x < y which have a value of true or false (i.e. the type of this expression is boolean) relational operators: >= == ‘<’ has type int x int  boolean