QUOTE(jack85 @ 17 Oct, 2007 - 10:48 AM)

A guys I need a function that when you are inputing for example 5.375, the binary output should be 0000010101100000. 00000101 for number 5 and 01100000 for 0.375. please I need your help to create my function.
Here is also my program:
CODE
import java.io.*;
public class BynaryFloat
{
/** Creates a new instance of BynaryFloat */
public BynaryFloat()
{
}
public static void main(String[] args)throws IOException
{
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.println("What do you want the program to do?");
System.out.println(" Decimal to binary ... 1");
System.out.println(" Binary to decimal ... 2");
String choice = input.readLine();
float c = Integer.parseInt(choice);
if(c==1)
{
System.out.println(" Enter a decimal number:");
String dba=input.readLine();
int db = Integer.parseInt(dba);
System.out.println(db);
int [] m = new int [10];
int j;
for(j=8;j>=1;j--)
{
m[j] = db%2;
db = db/2;
}
float sc = 0;
for(j=1;j<=8;j++)
{
if(m[j]==0)
{
if(sc==0)
{
continue;
}
}
System.out.print(+m[j] + " ");
sc = sc+1;
}
}
if(c==2)
{
System.out.println("Enter a binary number");
String bda=input.readLine();
float l=bda.length()-1;
double sum =0;
for(int w =0;w<bda.length();w++)
{
char r = bda.charAt(w);
String str = new Character®.toString();
float er = Integer.parseInt(str);
sum = sum + (er*Math.pow(2,l));
l--;
}
String zero = "";
for (int i = 0; i < 16 - bda.length(); i++)
{
zero = zero + "0";
}
bda = bda + zero;
System.out.println("The decimal is : "+sum);
}
}
private static String Zeroes(String bda)
{
String zero = "";
for (int i = 0; i < 16 - bda.length(); i++)
{
zero = zero + "0";
}
bda = bda + zero;
return bda;
}
}
I have to input 16 bit number 0000010101100000 as a input, and a program have to take first 8 bit numbers 00000101 and convert it to decimal(answer is 5) and after that have to put a point(.) and select next 8 bits 01100000 and this number should work as floating point and it should give you 0.375
So the answer of my program is 5.375
That what my program have to do.
My instructor told us to Write a conversion program for a decimal number to binary and vice versa. Binary numbers are of 16 bits: 8 bits for the whole number and 8 bits for the decimal part.
Please I need your help to creat a function that can do what I wrote above.
Please help to creat it.