Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-19-2012, 04:04 AM   PM User | #1
shadefire
New to the CF scene

 
Join Date: Mar 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
shadefire is an unknown quantity at this point
Binary number to a decimal equivalent

Hello, I started java a few weeks ago for my programming class, and I got this assignment where I had to convert a binary number to an integer, or its decimal equivalent. We are not allowed to use shortcuts to convert a binary to a decimal, or import anything other than java.io.*; I know how the binary system works, but I just don't know how to implement it and make it into a program using java. Does anybody have any idea how I can approach this problem? Any help is appreciated thanks.
shadefire is offline   Reply With Quote
Old 03-20-2012, 08:25 AM   PM User | #2
smithdavid
New to the CF scene

 
Join Date: Mar 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
smithdavid is an unknown quantity at this point
I know the simple coding,

import java.lang.*;
import java.io.*;
public class DecimalToBinary{
public static void main(String args[]) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the decimal value:");
String hex = bf.readLine();
int i = Integer.parseInt(hex);
String by = Integer.toBinaryString(i);
System.out.println("Binary: " + by);
}
}
smithdavid is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:32 PM.


Advertisement
Log in to turn off these ads.