• Log in or sign up for an account here: https://www.sythe.org/login

Challenge to new programmers!

Xeox

Forum Addict

Banned
Joined
Jun 17, 2010
Sythe Gold
0
Messages
357
Location
United States
Make a program that prints out the binary representation of an integer. Does not have to deal with negatives. I will post my way of solving this in a week, maybe sooner. Oh and no it's not a homework assignment of mine!
 
I think the point of this is to write your own algorithm that converts an integer to binary :P

Yea, it was a practice question for my first College CS exam, and I just thought it would liven things up a bit in the Java forum.
 
didn't realize you could directly convert integers to hex, octal and binary so easily
 
Le Monkey
PHP Shit Show 2k26
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
Code:
public void intbin(int input)
{
    int i;
    for(i = 0; i < 32; i++)
    {
        System.out.print(( input >> 31)&1);
        input <<= 1;
    }
    System.out.print("\n");
}
whadu i win
 
import javax.swing.*;
public class DecToBin{
public static void main(String [] args){
int numDec=0
String numBin="";
numDec=Integer.parseInt(JOptionPane.showInputDialog("Enter a number:"));
while(numDec>=1)
{
if(numDec==1){
numBin="1"+numBin; break;
}
else{
if(numDec%2==0)
{ numBin="0"+numBin;numDec/=2;}
else
{ numBin="1"+numBin;numDec/=2;}
}
}
JOptionPane.showMessageDialog(null,"Binary Number:"+numBin);
System.exit(0);
}
}
//i hope that this will work ^_^
 
There are two binary representations, a mathematical and a computational.

where 000... is -2,147,000,000 or something in computational
and on a mathematical base 32 zeros would be 2^32.
Which one are you referring to?
 
Runescape Gamblingrunescape gambling
Back
Top