Quiet afternoon at work (which is quite rare), so I wrote a little java program that converts from integer to binary to float.
public class PracticeMain {
public static void main(String[] args) {
int number = 26;
int remainder;
String output = "";
while(number > 1)
{
remainder = number%2;
output = (Integer.toString(remainder)) + output;
number = number/2;
}
output = (Integer.toString(number)) + output;
System.out.print(output);
StringBuffer outputString = new StringBuffer(output);
outputString.reverse();
output = outputString.toString();
double floatnum = 0;
for(int i= output.length(); i > 0 ; i--)
{
if(output.charAt(i-1) == '1')
{
floatnum = floatnum + Math.pow(2, (i-1));
}
}
System.out.println();
System.out.println(floatnum);
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment