Linked Questions

410 votes
10 answers
688k views

Declaring an unsigned int in Java

Is there a way to declare an unsigned int in Java? Or the question may be framed as this as well: What is the Java equivalent of unsigned? Just to tell you the context I was looking at Java's ...
Harshdeep's user avatar
  • 5,674
378 votes
5 answers
49k views

Why is "final" not allowed in Java 8 interface methods?

One of the most useful features of Java 8 are the new default methods on interfaces. There are essentially two reasons (there may be others) why they have been introduced: Providing actual default ...
Lukas Eder's user avatar
  • 216k
73 votes
16 answers
119k views

Unsigned short in Java

How can I declare an unsigned short value in Java?
maiky's user avatar
  • 3,553
55 votes
9 answers
16k views

Are there any real life uses for the Java _signed_ byte primitive type?

For some inexplicable reason the byte primitive type is signed in Java. This mean that valid values are -128..127 instead of the usual 0..255 range representing 8 significant bits in a byte (without ...
Thorbjørn Ravn Andersen's user avatar
26 votes
2 answers
60k views

Signed and unsigned data types in java

I have a bit of confusion regarding which unsigned data types does Java support? I have read Why doesn't Java support unsigned ints? but I don't understand its very complicated explanation (to me ...
ReflectionHack's user avatar
22 votes
3 answers
16k views

Why doesn't Kotlin support unsigned integers?

I came across a situation just recently in which an unsigned integer would have been really useful (e.g. any negative value would not make sense etc.). Surprisingly, I discovered that Kotlin does not ...
starbeamrainbowlabs's user avatar
21 votes
1 answer
1k views

Why isn't common_type<long, unsigned long>::type = long long?

common_type<long, unsigned long>::type is unsigned long because concerning the operands after integral promotion the standard says... [...] if the operand that has unsigned integer type has ...
David's user avatar
  • 27.9k
20 votes
6 answers
28k views

Port of Random generator from C to Java?

George Marsaglia has written an excellent random number generator that is extremely fast, simple, and has a much higher period than the Mersenne Twister. Here is the code with a description: good C ...
martinus's user avatar
  • 17.9k
13 votes
8 answers
8k views

When to use different integer types?

Programming languages (e.g. c, c++, and java) usually have several types for integer arithmetic: signed and unsigned types types of different size: short, int, long, long long types of guaranteed and ...
Michael's user avatar
  • 41.6k
10 votes
4 answers
3k views

Why no readUnsignedInt in RandomAccessFile class?

I just found there is no readUnsignedInt() method in the RandomAccessFile class. Why? Is there any workaround to read an unsigned int out from the file? Edit: I want to read an unsigned int from ...
5YrsLaterDBA's user avatar
10 votes
4 answers
4k views

Is Java's lack of unsigned primitive types a characteristic of Java the platform or Java the language?

There are questions about why Java doesn't support unsigned types and a few questions about dealing with unsigned types. I did some searching, and it appears that Scala also doesn't support unsigned ...
Thomas Owens's user avatar
9 votes
6 answers
9k views

Hashtable hashing avoid negative hashcode

I am wondering why does Hashtable avoid using negative hashcode ? int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; Where (hash & 0x7FFFFFFF) makes the signed bit to ...
peter's user avatar
  • 8,383
6 votes
3 answers
8k views

C# Marshal.Copy Intptr to 16 bit managed unsigned integer array

Why does C# Marshal.Copy routine does not have any overload for copying from unmanaged memory pointer to 16 bit managed unsigned integer array? ex: Copy(IntPtr, Byte[], Int32, Int32) Copies data ...
Dwight Schrute's user avatar
4 votes
1 answer
1k views

Converting CRC 8 function written in C to Java

I am trying to translate a CRC8 function from C to Java. I got this code from the hardware manufacturer: uint8_t CRCCalc (uint8_t* pointer, uint16_t len) { uint8_t CRC = 0x00; uint16_t tmp; ...
Nikita G.'s user avatar
3 votes
2 answers
2k views

Bytes in Java with hex

buffer is a bytebuffer .I'm getting a lost of percision error with this. byte myPort = buffer.get(0); // Might need to change this depending on byte order switch(myPort){ case 0xF1: //...
Dr.Knowitall's user avatar
  • 10.3k

15 30 50 per page