Linked Questions

9 votes
3 answers
12k views

How to output the absolute value of an Unsigned integer in java [duplicate]

I want to assign 4294967295 to a variable (2^32-1) It is obvious that I can't do that with Integer, and can do it with Long. However, I noted that Java 8 offers Unsigned Integers (at least some ...
Pubudu Dodangoda's user avatar
0 votes
0 answers
77 views

Can unsigned integer vaule is there in java? if then how to declare it? [duplicate]

Can we have unsigned Integer value in java?If value is there then how to declare it.
Shishadri Ray's user avatar
0 votes
0 answers
22 views

How to implement struct.unpack in Java with Integer type? [duplicate]

Following the similar question, I am trying to implement the unpack method in Java for Integer: Sample byte array input: chunkByte[1219:1240] = [64, 30, 31, 0, 64, 118, 31, 0, 64, -22, 29, 0, 64, 4, ...
newbie5050's user avatar
408 votes
17 answers
127k views

Why doesn't Java support unsigned ints?

Why doesn't Java include support for unsigned integers? It seems to me to be an odd omission, given that they allow one to write code that is less likely to produce overflows on unexpectedly large ...
dsimcha's user avatar
  • 68.1k
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
93 votes
5 answers
137k views

How to use the unsigned Integer in Java 8 and Java 9?

In the Oracle "Primitive data types" page, it mentions that Java 8 adds support for unsigned ints and longs: int: By default, the int data type is a 32-bit signed two's complement integer, ...
Pabce's user avatar
  • 1,429
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
14 votes
7 answers
22k views

Purpose of byte type in Java

I read this line in the Java tutorial: byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte ...
Hải Phong's user avatar
  • 5,104
5 votes
4 answers
8k views

Are byte arrays initialised to zero in Java?

In the following line, can buffer be assumed to be filled with zeroes? byte buffer[] = new byte[120];
Andreas's user avatar
  • 7,540
13 votes
1 answer
26k views

Unsigned Int in Java

I'm trying to implement an existing network protocol which makes heavy use of Unsigned datatypes, which are not supported by Java. What I currently do is for each datatype, chose the next bigger one ...
cdecker's user avatar
  • 4,577
4 votes
2 answers
7k views

Java left shift and fill with Zeros

I want to do left shifting but filling with zero, just like int number = 20 >>> 10 = ( 0000 0000 0000 0000 0000 0000 0001 0100 ) int number = 20 >>> 32‎ = ( 0000 0000 0000 0000 ...
computerSPro's user avatar
6 votes
3 answers
768 views

Why is List<T>.Count a signed int? Can List<T>.Count ever be negative?

public class List<T> { public int Count { get; } } I noticed Count is an int, will the result be less than 0? If Count could be less than 0, I have to write ...
Hanley's user avatar
  • 91
0 votes
2 answers
5k views

how to do big endian to little endian byte swap in Java

My data is stored as an int in java. <32bit signed>, which represents an unsigned 16bit value that is always positive. Big Endian decimal 253 stored as 16bit unsigned hex character 0x00FD is ...
jetro57070's user avatar
3 votes
5 answers
1k views

Seconds since 12:00 am December 31, 1989 Java

I have to get the count of seconds since 12:00 am December 31, 1989, to now. The second parser comes from Garmin Fleet Management. Here is my code: public int getDate(){ Date d1 = new Date(1989, ...
Sahee's user avatar
  • 43
3 votes
3 answers
273 views

Why would this simple java code not compile?

I had this question on a software development quiz and I'm not sure the reasoning behind the answer. unsigned int x = 1; while(x > 10) { System.out.print(x); x++; } ...
John Luke Garofalo's user avatar

15 30 50 per page