Numbers How does computer understand numbers? Knows only two symbols

Slides:



Advertisements
Similar presentations
1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public.
Advertisements

Arithmetic & Logic Unit Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point.
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 4.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Lecture 8 Floating point format
Lecture 12: Computer Arithmetic Today’s topic –Numerical representations –Addition / Subtraction –Multiplication / Division 1.
Computer Systems 1 Fundamentals of Computing Negative Binary.
Binary numbers and arithmetic. ADDITION Addition (decimal)
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
1 Please switch off your mobile phones. 2 Data Representation Instructor: Mainak Chaudhuri
Dale & Lewis Chapter 3 Data Representation. Data and computers Everything inside a computer is stored as patterns of 0s and 1s Numbers, text, audio, video,
Calculating Two’s Complement. The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Number systems, Operations, and Codes
Positional Number Systems
1 Conditionals Instructor: Mainak Chaudhuri
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Variables, Arithmetic, etc.)
Mixing integer and floating point numbers in an arithmetic operation.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
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=
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Binary Arithmetic.
IT1004: Data Representation and Organization Negative number representation.
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.
WELCOME To ESC101N: Fundamentals of Computing Instructor: Ajai Jain
1 Conditionals Instructor: Mainak Chaudhuri
Computer Organization 1 Data Representation Negative Integers.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Binary Arithmetic James A. Rome Tennessee Governor's Academy August 2010.
973cs111_add_posneg.ppt Integers Whole numbers Do NOT contain decimal points (as in money) 43,689 is an integer 43, is NOT an integer (it is floating.
Unit I From Fundamentals of Logic Design by Roth and Kinney.
Representing Positive and Negative Numbers
Chapter 9 Computer Arithmetic
Floating Point Representations
Department of Computer Science Georgia State University
Topic: Binary Encoding – Part 2
Cosc 2150: Computer Organization
Chapter 2 Binary Number Systems.
David Kauchak CS 52 – Spring 2017
Negative Binary Numbers
Digital Systems and Number Systems
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Computer Science 210 Computer Organization
Numbers in a Computer Unsigned integers Signed magnitude
ITEC113 Algorithms and Programming Techniques
Computer Architecture & Operations I
Negative Binary Numbers
CSE 102 Introduction to Computer Engineering
Binary numbers and arithmetic
Binary Addition & Subtraction
Computer Science 210 Computer Organization
Topic 3 Number Representations and Computer Arithmetics
ECEG-3202 Computer Architecture and Organization
Numbers and Arithmetic and Logical Operation
Unit 18: Computational Thinking
COMS 161 Introduction to Computing
Topic 3 Number Representations and Computer Arithmetics
Number Systems.
Decimal and binary representation systems
Chapter 8 Computer Arithmetic
Chapter 6: Computer Arithmetic
Number Systems Rayat Shikshan Sanstha’s
CSC 220: Computer Organization Signed Number Representation
Numbers and Arithmetic and Logical Operation
COMS 161 Introduction to Computing
GCSE COMPUTER SCIENCE Topic 3 - Data 3.3 Logical and Arithmetic Shifts.
Today Binary addition Representing negative numbers 2.
Presentation transcript:

Numbers How does computer understand numbers? Knows only two symbols We are mostly familiar with decimal numbers General number representation in arbitrary base An algorithm for converting between bases Special case: base=2 (binary) Is there a decimal to binary converter inside the computer? Compiler does it Negative numbers? Two representation conventions: sign-magnitude representation and 2’s complement representation

2’s complement Steps involved in converting decimal to 2’s complement Decide the number of bits (should be at least 2+integer part of log2|N|) Write the magnitude in binary and append zeros at the front to fill up the remaining bits (this is 2’s complement of the positive number) Flip all bits (this is 1’s complement of the positive number) Add 1 to it (this is 2’s complement representation of the negative number)

2’s complement 2’s complement to decimal: Write down the polynomial expansion in base 2 Append a negative sign to the leading coefficient Comparison of 2’s complement and sign-magnitude Range in sign-magnitude with n bits Range in 2’s complement with n bits Benefits of 2’s complement in binary arithmetic: will discuss later All computers and calculators use 2’s complement representation

if statement if (condition) { statements } Nested if if (condition1) {

/* Compute density and prevent division by zero */ class densityIf { public static void main (String args[]) { double mass, volume, density; mass = 27.2; volume = 0.0; density=0.0; if(volume<=0.0) System.out.println("Density cannot be computed as the volume is zero"); if(volume>0.0) System.out.println("Density of the liquid is: "+ mass/volume); }

Nested if Sometimes possible to simplify nested if if (condition1) { statements } Same as if ((condition1) && (condition2)) {

Example class exampleIf { public static void main(String arg[]) { int x=10, y, z; if ((x%2)==0) {System.out.println(x + “ is even.”); if ((x%3)==0) {System.out.println(x + “ is a multiple of 6.”); y = x/6; } z = x%6;