문제

i search in this site and other for converting double value like .4 to binary but there is no useful answers ! i know the procedure multiply by 2 if the number is bigger than 1 save the 1 subtract it and more time multiply it by 2 and so on . help me !

double d = .4 ; 
double e ;
while ()
{
e = d*2; 
if (e>1) {
s[i]= 1;
e=d-1;
} else {
s[i] = 0;
}
System.out.print(s[i]);
}
도움이 되었습니까?

해결책

Use Double.doubleToRawLongBits(double), and then Long.toBinaryString(long) on the result:

double d = 0.4;
System.out.println(Long.toBinaryString(Double.doubleToRawLongBits(d)));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top