A few things about Lab1 - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

A few things about Lab1

Description:

To add two decimal numbers you add the digits and if the total is greater than ... For negative numbers reverse 0s and 1s and then add 1 ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 15
Provided by: systema178
Category:
Tags: few | lab1 | numbers | things

less

Transcript and Presenter's Notes

Title: A few things about Lab1


1
A few things about Lab1
  • Worth 10 points
  • There is a two letter grade code in green. Use
    this to look up your grades online.
  • Read everything
  • Follow directions
  • Answer everything

2
Your turn 1
  • What unsigned decimal numbers are represented by
    the following binary numbers?
  • Example 00000101 5
  • 00000100
  • 00001101
  • 00110011
  • Answers 4, 13, 51

3
Your turn 2
  • How would you write the following numbers in
    binary?
  • Example 14 8 4 2 -gt 00001110
  • 3
  • 21
  • 43
  • Answers 00000011, 00010101, 00101011

4
Binary Addition
  • To add two decimal numbers you add the digits and
    if the total is greater than ten you carry the
    leading digit (with two number, always a 1) into
    the next column
  • To add two binary numbers
  • 0 0 0
  • 0 1 and 1 0 1
  • 1 1 10
  • Write down the zero and carry the 1 into the next
    column to the left
  • 00 10 111
  • 01 01 001
  • ---- --- ------
  • 01 11 1000
  • 00111001010
  • 01010101101
  • -------------------
  • 10001110111

5
2s Compliment Notation
  • Computers actually only know how to add
  • So, how do they handle subtraction?
  • Computers subtract by adding a negative number
  • How do you represent a negative number in memory?
  • Positive numbers in 2s compliment are just the
    same as a binary number
  • For negative numbers reverse 0s and 1s and then
    add 1
  • All negative numbers have a one for the leftmost
    bit

6
2s Compliment Example
  • To subtract 3 from 7
  • First represent both as a binary number
  • 7 is 0000 0111 (1 2 4)
  • 3 is 0000 0011 (1 2)
  • Reverse the 0s and 1s and then add 1 to get -3
  • 0000 0011 reversed is 1111 1100
  • add 1 0000 0001
  • The result is 1111 1101

7
Add the Negative Number
  • To subtract 3 from 7
  • Add -3 to 7
  • 7 is 0000 0111
  • -3 is 1111 1101
  • The result is 1 0000 0100
  • Through away the leftmost 1
  • The answer is 0000 0100 which is 4

8
Basic Data Types
  • Most languages start with a basic 4 types of data
    at the primitive level.
  • Integers (numbers without fractional parts)
  • Floating point numbers (numbers with fractional
    parts)
  • A single character
  • Booleans (True and false values)

9
As an example - Java Primitive Types
Data stored as 2s complement
10
As an example - Java Primitive Types
Data stored in IEEE 754
11
Decimal Number Storage
  • How do you think a computer stores 3205.406?
  • It uses an IEEE 754 format
  • Stored as binary numbers in scientific notation
    -52.202 is -.52202 x 102
  • For example
  • 6.5 in decimal
  • 110.1 in binary
  • .1101 x 23 in binary with scientific notation
  • Stores 3 things
  • A bit for the sign
  • A number between 0 and 1 (the mantissa)
  • The power of 2 (the exponent 8 bits)

12
Decimal Number Storage
  • The problem with this structure
  • Many numbers actually dont encode well
  • How would you encode 32.01??

13
As an example - Java Primitive Types
Data stored in ASCII
14
ASCII code
  • A simple conversion of the common American
    characters and computer commands to numbers.
  • A 65
  • a 97
  • 1 49
  • \t 11
  • See www.asciitable.com for more information
Write a Comment
User Comments (0)
About PowerShow.com