Here is what I have to do:
Problem
Given an integer number N (the number can be initialized in your program), write a JAVA
program that prints the binary representation of N.
Hint: The representation of integer numbers in binary (base 2) was explained and exemplified in
the lecture on September 5. For instance,
if N=264 you must print 0100001000;
if N=-264 you must print 1011111000;
if N=0 you must print 0.
Please remember that the most significant (leftmost) bit in the representation is the ”sign”
bit: 0 for positive numbers, 1 for negative numbers.
I have found 2 codes that will do this i think,
CODE
class binary{
public static void main (String[] args) {
System.out.print("Binary: ");
System.out.println(Integer.toBinaryString(-14));
}
}
CODE
class binarys{
public static void main (String[] args) {
int v = 8;
System.out.println( Integer.toString( v, 2 ));
System.out.println( Integer.toString( -v, 2 ));
}
}
Here is my problem.. niether one of these codes do what I need.. I need to actually show the number being converted in the code.
example:
264 : 2 = quotient 132 remainder 0
and so on you know divide the quotient till you have zero and use the remainders as binary representations.
Basically i need to show how it's done.. Not just do it.
If anybody can point me in the right direction on how to accomplish this I would very much appreciate it.
Thank you