Question

Convert the following numbers from binary to decimal: 101.101001    0.000101 1.0 Convert the following numbers...


Convert the following numbers from binary to decimal:

101.101001   

0.000101

1.0

Convert the following numbers from decimal to binary:

12.28125

0.0234375

0.7

***If you could show some of the work so I can understand how to do this better, that would be greatly appreciated.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


import java.util.Scanner;
public class example {


public static void main(String[] args) {
  
Scanner sc = new Scanner( System.in );
System.out.println("enter binary: ");

float bnum=sc.nextFloat();
float bnry=bnum;
  
int dec = 0;
int pow = 0;

while(true){

if(bnry == 0){

break;

} else {

float tmpr = bnry%10;
dec += tmpr*Math.pow(2, pow);
bnry = bnry/10;
pow++;

}
}
System.out.println("binary is:="+bnry+" decimal is:="+dec); ;
}

}
ouput:
enter binary:
01
binary is:=0.0 decimal is:=1
enter binary:
1.0
binary is:=0.0 decimal is:=1




import java.util.Scanner;
public class example {


public static void main(String[] args) {
  
   int i = 12;

String num = Integer.toBinaryString(i);
  
System.out.println("decimal to binary:");
System.out.println("val is:" + i + " is :" +num);
  
}

}
output:
decimal to binary:
val is:12 is :1100

Add a comment
Know the answer?
Add Answer to:
Convert the following numbers from binary to decimal: 101.101001    0.000101 1.0 Convert the following numbers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT