Number Conversion - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Number Conversion

Description:

a[:2] ['bacon', 2*2] will give ['spam', 'eggs', 'bacon', 4] List can be modified. ... We call string, list, and dictionary 'Sequence Types'. Operations: ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 16
Provided by: pagesCpsc
Category:
Tags: and | bacon | conversion | eggs | number

less

Transcript and Presenter's Notes

Title: Number Conversion


1
Number Conversion
  • Binary 0,1
    Base2
  • Decimal 0,1,2,3,4,5,6,7,8,9 Base10
  • Octal 0,1,2,3,4,5,6,7 Base8
  • Hexadecimal 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
    Base 16

2
Converting From Decimal to Binary
  • Dividing decimal number by 2.
  • Example Convert 123 into binary.

3
Converting Decimal To Octal
  • Dividing decimal number by 8.
  • Example Convert 123 into octal.

4
Converting Decimal To Hexadecimal
  • Dividing decimal number by 16.
  • Example Convert 123 into hex.

5
Converting Hexadecimal to Binary
  • Using the number table.
  • Convert 1AB to binary.

6
Converting Octal to Binary
  • Using the same table.
  • Convert 175 to binary.

7
Binary to Decimal
  • For each digit, multiply by 2 to the power of the
    digit position.
  • Convert 10111 to decimal.

8
Octal to Decimal
  • For each digit, multiply by 8 to the power of the
    digit position.
  • Convert 163 to decimal.

9
Hexadecimal to Decimal
  • For each digit, multiply by 16 to the power of
    the digit position.
  • Convert 1AC to decimal.

10
Python- Numbers
  • Integer 1, 2,9,-1,100
  • Float 1.2,10.13, 3.141596
  • Operations on numbers , -, , , and /

11
Python- String
  • word 'hello world'
  • Strings can be subscripted
  • word1 will give 'e'
  • word03 will give 'hel'
  • word4 will give 'hell'
  • strings cannot be changed !
  • word1 'E' is invalid!!!

12
Python - List
  • a 'spam', 'eggs', 100, 1234
  • a0 will give 'spam'
  • a3 will give 1234
  • a2 'bacon', 22 will give 'spam', 'eggs',
    'bacon', 4
  • List can be modified. A1 12345 will give
    'spam', 12345, 100, 1234

13
Python - Dictionary
  • A dictionary is collection of ltkey, valuegt pairs.
  • MyDictionary "one" 2, "two" 3
  • .items() return a copy of the dictionarys list
    of (key, value) pairs.

14
Python - Sequence Types
  • We call string, list, and dictionary Sequence
    Types.
  • Operations
  • x in s True if an item of x is in s, else False
  • x not in s False if an item of x is in s, else
    True
  • s t the concatenation of s and t
  • len(s) length of s

15
Convert String to numbers
  • S '1', to convert S into integer
    whatever_the_name_you_like int(S). To convert
    S into float X float(S)?
Write a Comment
User Comments (0)
About PowerShow.com