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.

Results 1 to 3 of 3

Thread: Finding the binary of negative numbers

  1. #1
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Finding the binary of negative numbers

    How do u find the binary of negative numbers? I already did it for positive numbers, and help?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Finding the binary of negative numbers

    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 ---

    From a PM: Concerning the negative binary numbers, i got the answer.
    Please mark this thread as SOLVED if you have the answer.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Finding the binary of negative numbers

    Quote Originally Posted by Java girl View Post
    How do u find the binary of negative numbers?
    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 AM.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

Similar Threads

  1. Adding and Subtracting positive or negative two numbers of any length with strings
    By javabeginner63 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 5th, 2014, 05:11 PM
  2. (Java) Help with alternating negative and positive numbers.
    By fcknDan in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 16th, 2013, 12:48 AM
  3. catch negative numbers
    By garry in forum Exceptions
    Replies: 6
    Last Post: November 8th, 2013, 10:05 PM
  4. Have trouble dealing with negative numbers.
    By Arick Cheng in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 29th, 2012, 07:41 AM