| | |
Conversion
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 53
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: 53
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: 53
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
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






