How do u find the binary of negative numbers? I already did it for positive numbers, and help?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
How do u find the binary of negative numbers? I already did it for positive numbers, and help?
Can you explain what you want the code to do?
Are you trying to create a String of binary digits (0s and 1s) from a number like an int?
--- Update ---
Please mark this thread as SOLVED if you have the answer.From a PM: Concerning the negative binary numbers, i got the answer.
First, at binary level, there is no "negative" or "positive". Binary is 0s and 1s. Stop.
The knowledge of "negative" is given by a specific representation (on a word of N bits), that is mainly implicit on every microprocessor. The most and well known is the "Two's complement" representation.
So if you have an int in Java, you have 32 bits. You can print these 32 0s/1s regardless the fact that the number is positive or negative.
And if you mean to print e.g. -1100 to say -12 in binary, it's ok but this is your choice/notation and it's not the same as the raw bits in a two's complement representation.
Last edited by andbin; March 22nd, 2014 at 11:58.