Character Encoding - PowerPoint PPT Presentation

About This Presentation
Title:

Character Encoding

Description:

Character Encoding & Handling doubles Pepper Character encoding schemes EBCDIC older with jumps in alphabet ASCII 1967 (7 bit) Handled English, ASCII extended ... – PowerPoint PPT presentation

Number of Views:122
Avg rating:3.0/5.0
Slides: 12
Provided by: Joan3221
Learn more at: https://home.adelphi.edu
Category:

less

Transcript and Presenter's Notes

Title: Character Encoding


1
Character Encoding Handling doubles
  • Pepper

2
Character encoding schemes
  • EBCDIC older with jumps in alphabet
  • ASCII 1967 (7 bit) Handled English,
  • ASCII extended (8 bit) handled special
    characters such as ñ and
  • UNICODE (16 bits) all language not Klingon,
    Egyption hieroglyphics (sometimes uses fewer bits)

3
Print Unicode table
  • Create a for loop to run 340 times
  • Convert count to char with a cast
  • char x (char) count
  • Print "When the number is " count " the
    character is " x
  • Be sure to set unlimited buffering on your BlueJ
    window.

4
character printing code
  • public class characters
  • public static void main()
  • for (int count 1 count lt 500 count)
  • char x (char) count
  • System.out.println("When the number is " count
    " the character is " x)

5
Doubles not exact
  • Stored binary, so .41 is actually a repeating
    sequence starting with .01101000111101011100001010
    001111
  • http//www.mathsisfun.com/binary-decimal-hexadecim
    al-converter.html
  • To explain how decimal portions convert
  • http//www.mathsisfun.com/base-conversion-method.h
    tml

6
Converting 41/100 to binary
Place Equation Result
1 Note decimal .
2 .412 .82 0
3 .822 1.64 1
4 .642 1.28 1
5 .282 .56 0
Result a repeating pattern of
.01101000111101011100001010001111
7
doubles check equal
  • small differences mean little errors creep in.
  • Math.abs(dollars1 - dollars2) lt .001
  • ex Write a program to Multiply .41 .41 and
    compare it to .1681
  • print the values so you see the diff
  • try an comparison to see it fail
  • try the test for no more than .001 off

8
double check equal
  • public class testdouble
  • public static void main()
  • double x .41.41
  • double y .1681
  • System.out.println("x is " x " and y
    is " y)
  • if (x y)
  • System.out.println("match with equal
    sign")
  • else
  • System.out.println("no match with
    equal sign")
  • if (Math.abs(x-y)lt .001)
  • System.out.println("match")

9
printing double
  • System.out.printf("x is .2f ", x)
  • OR
  • import java.text.DecimalFormat
  • DecimalFormat twoDec new DecimalFormat("0.00")
  • System.out.println("x is " twoDec.format(x))

10
More on Decimal Formatter
  • DecimalFormatter object knows How to print
    decimals
  • Package to import import java.text.DecimalFormat
  • How to create a DecimalFormatter for your
    numbers
  • DecimalFormat percentage2 new
    DecimalFormat(0.00)
  • How to use a DecimalFormatter to print to your
    screen
  • System.out.println(percentage2.format(.308)) //
    will print 30.80
  • Different format options
  • 0 required position
  • show it if you have it
  • make it a (mult by 100)
  • E E notation (scientific)
  • Now you change your program to print x with only
    2 decimal places

11
Printf
  • printf command
  • Just like println, but uses variables inside
    string start and end character.
  • , then size of whole number, then decimal places
    and then type
  • d int
  • f float
  • s string
  • c char
Write a Comment
User Comments (0)
About PowerShow.com