| | |
Conversion
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 54
base http://java.sun.com/docs/books/jls/
also explore javadoc,sourcecode of ==>java.lang.Float ,java.lang.Double
funny number, isn't it?
Float f = -Float.MIN_VALUE;
Integer i = Float.floatToIntBits(f);
System.out.println(Integer.toBinaryString(i));
System.out.println(Integer.toHexString(i));
Integer j = Float.floatToRawIntBits(f);
System.out.println(Integer.toBinaryString(i));
System.out.println(Integer.toHexString(i));
//10000000000000000000000000000001funny number, isn't it?
•
•
Join Date: Sep 2008
Posts: 34
Reputation:
Solved Threads: 0
•
•
•
•
base http://java.sun.com/docs/books/jls/
also explore javadoc,sourcecode of ==>java.lang.Float ,java.lang.DoubleFloat f = -Float.MIN_VALUE; Integer i = Float.floatToIntBits(f); System.out.println(Integer.toBinaryString(i)); System.out.println(Integer.toHexString(i)); Integer j = Float.floatToRawIntBits(f); System.out.println(Integer.toBinaryString(i)); System.out.println(Integer.toHexString(i)); //10000000000000000000000000000001
funny number, isn't it?
I have IEEE754 representation of real number 2.5 as follows:
01000000001000000000000000000000
How can I retrieve 2.5 back from this representation?
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 54
IEEE754 Float Bits:
0 10000000 01000000000000000000000
Divide to 3 parts (sign, exponent, fraction) .Parse them separately. PICTURE http://en.wikipedia.org/wiki/IEEE_754-1985
Once more read all your posts on the same theme and write at end your code.
(even start point of your code)
0 10000000 01000000000000000000000
Divide to 3 parts (sign, exponent, fraction) .Parse them separately. PICTURE http://en.wikipedia.org/wiki/IEEE_754-1985
Once more read all your posts on the same theme and write at end your code.
(even start point of your code)
Last edited by quuba; Dec 29th, 2008 at 10:49 am. Reason: added last line
•
•
Join Date: Dec 2008
Posts: 53
Reputation:
Solved Threads: 6
You don't actually have to go to all that trouble, though...
Java Syntax (Toggle Plain Text)
int val = Integer.parseInt(str, 2); float f = Float.intBitsToFloat(val);
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 54
step by step
You have a String of length =32 on input
You need 3 substrings as result.
Fill the split() method using String-class methods.
You have a String of length =32 on input
You need 3 substrings as result.
java Syntax (Toggle Plain Text)
public class StringSplitter { //0 10000000 01000000000000000000000 //Divide to 3 parts (sign, exponent, fraction) .Parse them separately private String s32; // source string // parts of string private String sign; private String exponent; private String fraction; public StringSplitter(String s32) { this.s32 = s32; split(); } private void split() { //TODO //0 10000000 01000000000000000000000 //sign= exponent= fraction= // xxx = s32.substring(beginIndex, endIndex) } public String toString() { StringBuffer sb = new StringBuffer(); sb.append("source string= "); sb.append(s32); sb.append(" sign= "); sb.append(sign); sb.append(" exponent= "); sb.append(exponent); sb.append(" fraction= "); sb.append(fraction); return sb.toString(); } public static void main(String[] args) { String inputString = "01000000001000000000000000000000"; StringSplitter ss = new StringSplitter(inputString); System.out.println(ss); } }
•
•
Join Date: Sep 2008
Posts: 34
Reputation:
Solved Threads: 0
•
•
•
•
You don't actually have to go to all that trouble, though...
Java Syntax (Toggle Plain Text)
int val = Integer.parseInt(str, 2); float f = Float.intBitsToFloat(val);
Thank you very much!!!
![]() |
Similar Threads
- Conversion (VB.NET)
- Google's AdWords Conversion Tracking System (Pay-Per-Click Advertising)
- Are You Using These Keyword Selection Guidelines to Improve Website Conversion Rates? (Search Engine Optimization)
- Need help with this conversion program (C++)
- code conversion from c\c++ to java (C++)
- Java to C# Conversion (C#)
- project conversion (C++)
- Tower to Rack conversion Kit (Networking Hardware Configuration)
- Pounds to Grams Conversion (C++)
Other Threads in the Java Forum
- Previous Thread: java vs .net
- Next Thread: BFS in Applet
Views: 656 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android animated api appinventor apple applet application arguments array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component database draw eclipse error event exception file fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javaprojects jetbrains jmf jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie notdisplaying number object oracle page print problem program programming project qt recursion scanner screen server set size sms socket sort spamblocker sql string swing system test threads time transfer tree variablebinding windows xor






