number representation in java
play

Number representation in Java Scientific notation Overview topics - PowerPoint PPT Presentation

Number representation in Java DOS, HOM Its about interpretation Number representation in Java Scientific notation Overview topics Binary representation of Thijs Dorssers, Pieter van den Hombergh integers Binary representation of


  1. Number representation in Java DOS, HOM It’s about interpretation Number representation in Java Scientific notation Overview topics Binary representation of Thijs Dorssers, Pieter van den Hombergh integers Binary representation of Fontys Hogeschool voor Techniek en Logistiek floats Binary June 15, 2017 representation of floats Binary representation of floats Links and exercises Links and exercises DOS, HOM/FHTenL Number representation in Java June 15, 2017 1/10

  2. Number It is just a bunch of bits representation in Java But what they represent depends on the interpretation. DOS, HOM eg 0b 01100010 01110101 01110011 01111001 : It’s about interpretation is 1651864441 when interpreted as integer Scientific notation is 1,13194324E21 when interpreted as floating point Overview topics (float) Binary representation of “busy” when interpreted as a string. integers Binary So the meaning of a set of bits depend on their intended representation of floats interpretation. These bits themselves have no clue. Binary Remember that. representation of floats Binary representation of floats Links and exercises Links and exercises DOS, HOM/FHTenL Number representation in Java June 15, 2017 2/10

  3. Number Scientific notation representation in Java How is 0,1 written in scientific notation? DOS, HOM Scientific notation is: It’s about interpretation mantissa ∗ base exponent Scientific notation In the decimal number system thus base = 10, mantissa Overview topics always has exactly 1 digit before the decimal mark. Binary representation of This decimal mark depends on the country you are: integers Binary US and UK this is a . (dot) representation of floats Germany and the Netherlands this is a , (comma) Binary Examples: representation of floats 100 = 1E2 Binary avogadro’s number 602.214.130.000.000.000.000.000 = representation of floats 6,0221413e+23 Links and exercises See: https://www.youtube.com/watch?v=Dme-G4rc6NI Links and exercises Some details will be written on the blackboard, thus jot down notes. DOS, HOM/FHTenL Number representation in Java June 15, 2017 3/10

  4. Number See NumberRepresentation in demos repository representation in Java folder DOS, HOM In this java code the following topics will be discussed: It’s about interpretation 1 Scientific notation Scientific notation 2 Inaccurate double and float calculations Overview topics Binary 3 Accurate calculations with big decimals representation of integers 4 Infinite versus finite Binary representation of 5 Binary representation of integers floats 6 Integer addition, subtraction, multiplication, division Binary representation of (decimal and binary) floats Binary 7 Binary representation of floats representation of floats Some details will be written on the blackboard, thus jot Links and exercises down notes. Links and exercises DOS, HOM/FHTenL Number representation in Java June 15, 2017 4/10

  5. Number Binary representation of integers representation in Java An integer in java is a so-called ”32-bit signed two’s DOS, HOM complement integer”. It’s about First bit is not a sign bit, although being 0 for positive interpretation Scientific notation numbers and 1 for negative numbers. Some people call it a Overview topics sign bit, but as you know as a mathematician one has to be Binary very precise. representation of integers Based on the circle model the 2 complements 4 bits number Binary system will be explained on the black board, here you can representation of floats easily deduct the bit representation of negativ numbers. Binary A trick: representation of floats To get the bit representation of a negative number do: Binary 1 Determine bit representation of the belonging positive representation of floats number Links and exercises 2 Replace all zero’s by ones and all one’s by zero’s Links and exercises 3 Add 1 to the result of step 2 Some details will be written on the blackboard, thus jot down notes. DOS, HOM/FHTenL Number representation in Java June 15, 2017 5/10

  6. Number Binary representation of floats IEEE 754 representation in Java On the black board: 32 bit internal representation of 0,1 DOS, HOM Decimal 0,1 = 1/16 + 1/32 + 1/256 (see spreadsheet It’s about 0.1 in binary form.xlsx) and in binary form 0,00011001.... interpretation Scientific notation These dots express an infinite series of 0 and 1. Overview topics Binary So not every finite series of decimals can be expressed with a representation of integers finite series of bits. Binary Computer internal representation of 0,1: representation of floats (1 bit) sign bit = 0 Binary representation of (23 bits) mantissa = 1,1001... and normalized mantissa floats = 1001.. Binary representation of (8 bits) exponent = -4, and biased exponent = -4+127 floats Links and exercises is decimal 127 - 4 = binary 01111111 - 100 = 01111011 Links and exercises Check this with http://www.binaryconvert.com Some details will be written on the blackboard, thus jot down notes. DOS, HOM/FHTenL Number representation in Java June 15, 2017 6/10

  7. Number More examples representation in Java On the black board: DOS, HOM convert IEEE754 binary It’s about interpretation 11000001111000000000000000000000 to decimal Scientific notation convert decimal 12.375 to IEEE754 binary Overview topics use http://www.h-schmidt.net/FloatConverter/ Binary representation of IEEE754.html to find the accuracy of the 32 bit integers IEEE754 representation of 0.3 Binary representation of floats exam examples Binary representation of floats Binary representation of floats Links and exercises Links and exercises DOS, HOM/FHTenL Number representation in Java June 15, 2017 7/10

  8. Number Solutions of more examples representation in Java signbit=-, exponent: 10000011=131, 131-127=4, DOS, HOM mantissa=1.110000000000000=1.75 result=-28 It’s about interpretation 12.375=1100.011, mantissa=1.100011, Scientific notation normalized=100011, exponent=3, biased Overview topics exponent=130=10000010, signbit=0 Binary result=01000001010001100000000000000000 representation of integers transformed back we get 0.30000001192092896, Binary representation of accuracy 7 decimals after the decimal dot floats Binary representation of floats Binary representation of floats Links and exercises Links and exercises DOS, HOM/FHTenL Number representation in Java June 15, 2017 8/10

  9. Number Links and exercises representation in Java For more information about float representation see DOS, HOM http://introcs.cs.princeton.edu/java/91float/ up to It’s about ”Rounding of decimal fractions”. interpretation A handy helper app is provided by Harald Schmidt on his Scientific notation site: Overview topics http://www.h-schmidt.net/FloatConverter/IEEE754.html. Binary Exercises: representation of integers 1 Given is the binary representation: -0.010011 Binary 2 Convert the binary representation of item 1 with pencil representation of floats and paper to a 32 bit IEEE 754 floating point Binary representation. representation of 3 Calculate the binary representation of -16.375 with floats pencil and paper Binary representation of 4 Convert the result of exercise 3 to a 32 bit IEEE 754 floats floating point representation. Links and exercises 5 Suppose you want to add the following 2 binary IEEE Links and exercises 754 floating point numbers, what’s than the problem? 0 10000000 1010000 00000000 00000000 0 10000010 1001100 00000000 00000000 DOS, HOM/FHTenL Number representation in Java June 15, 2017 9/10

  10. Number Solution of exercises representation in Java 1 - DOS, HOM 2 signbit=1, exponent=-2 biased It’s about interpretation exponent=125=64+32+16+8+4+1=01111101, Scientific notation mantissa=0.010011 normalized=0011 in 23 bit Overview topics 001100110011001100110011, Binary result=101111101001100110011001100110011 representation of integers 3 -16.375=-(16+0.25+0.125), binair=-10000.011, Binary transformation to IEEE754 is solved next representation of floats 4 signbit=1, exponent=4 biased=131=10000011, Binary mantissa=1.0000011, normalized=0000011, representation of floats result=11000001100000110000000000000 Binary 5 The problem is how to deal with the different representation of floats exponents? Links and exercises Links and exercises DOS, HOM/FHTenL Number representation in Java June 15, 2017 10/10

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend