negative « Integer « Java Data Type Q&A





1. Java negative int to hex and back fails    stackoverflow.com

public class Main3 {
    public static void main(String[] args) {
     Integer min = Integer.MIN_VALUE;
     String minHex = Integer.toHexString(Integer.MIN_VALUE);

   ...

2. How to convert a negative integer into two's complement binary form? (Java)    stackoverflow.com

I need to convert numbers, positive and negative, into binary format - so, 2 into "00000010", and -2 into "11111110", for example. I don't need more than 12 bits or so, ...

3. Packing two shorts into one int, dealing with negative and positive    stackoverflow.com

I'm making a class PackedUnsigned1616 which stores two unsigned shorts in one int, and a class PackedSigned1616 which stores two signed shorts in one int. I've read up on bitwise operations, ...

4. Parse a negative prefix integer from string in java    stackoverflow.com

Hi i have a string looking something like this 10 -1 30 -2 and i want to read the numbers between spaces. I can do this using a FOR statement and ...

5. Java math function to convert positive int to negative and negative to positive?    stackoverflow.com

Is there a Java function to convert a positive int to a negative one and a negative int to a positive one? I'm looking for a reverse function to perform this conversion:

-5 ...

7. Integer.toHexString() on a negative value ?    coderanch.com

I believe the below from the api states exactly what is happening toHexString Creates a string representation of the integer argument as an unsigned integer in base 16. The unsigned integer value is the argument plus 2^32 if the argument is negative; otherwise, it is equal to the argument. Hope that helps, Tom ------------------

8. Convert negative integer to byte[] and back    coderanch.com

Hi all, Like the subject says. Is there a way to convert negative integers (32-bit) to a byte array and then back? I don't know if there is an explicit way in a computer to determine if an integer is negative or not if not assuming that some bits of the integer represents the sign. I have only managed to convert ...

9. Negative int    coderanch.com





10. Why negative integers are so nasty in binary?    coderanch.com

Hello, Probably you know how the negative integers are stored in the memory. To remind it, if you want to get the binary representation (source): - First get the binary representation of the number. - Then interchange zeros and ones in the binary representation. - Finally add one to the result. So for example two's complement of -18 would be (assuming ...

11. string to negative int problem    java-forums.org

hey there first and foremost this is school related and if anyone has a problem with me asking for help then it is at their discretion whether or not to help me and if there is a problem with admin i can understand. As far as requests go i feel that this is very simplistic and would really only aid me ...

12. convert negative int to positive    java-forums.org

13. A program that throw an exception for negative integers and continues    forums.oracle.com

There are too many errors for me to fix, the worst being that you never even call a conversion routine -- rather you are "calling" variables (but that doesn't matter yet since those routines are broken). Rember to call a method it needs to have a parenthesis at the end. You need to start from square one. Do it slowly, one ...

14. How to stop a byte being interpreted as a negative int (double complement)?    forums.oracle.com

Thanks for the reply, yeah fis is a fileinputstream but I want to load the bytes into a byte array first and manipulate them. What I don't understand is that fis.read() on a byte with a value of "11111111" returns 255 (which is what I want) but when the byte is put into a byte array it now returns -1. I ...

15. Negative integers    forums.oracle.com

16. Int stays negative even when it is negated    forums.oracle.com