Java Reference
In-Depth Information
long t;
// Get user input
num = Keyin.inDouble(“Enter a floating-point double: ”);
binVal = Double.doubleToRawLongBits(num);
// Display hex bits
System.out.println(“As long=”+Long.toHexString(binVal));
// Display bit fields of double format
s = binVal & SIGN;
if(s != 0)
System.out.println(“Sign = -”);
else
System.out.println(“Sign = +”);
// Mask out exponent field
e = (binVal & EXPN);
eS = Long.toHexString(e);
System.out.println(“Exponent=”+eS);
// Mask out significand field
m = (binVal & SGNF);
eS = Long.toHexString(m);
System.out.println(“Significand=”+eS);
System.out.println(“\nFields in binary”);
if(s != 0)
System.out.println(”Sign bit = 1");
else
System.out.println(”Sign bit = 0");
// Display binary exponent
// Eliminate sign bit
e=e<1;
System.out.print(“Exponent = ”);
for(intk=0;k<11;k++)
{
t=e&BIT1;
// System.out.println(Long.toHexString(t));
if(t != 0)
System.out.print(“1");
else
System.out.print(“0");
e=e<1;
}
System.out.println(“\n
|-11 bits-|”);
// Display binary significand
// Eliminate exponent and sign bits
m=m<12;
System.out.print(“Significand = 1.”);
for(intj=0;j<51;j++)
{
t=m&BIT1;
Search WWH ::




Custom Search