aspose file tools*
The moose likes Beginning Java and the fly likes Unsigned integers in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unsigned integers in Java" Watch "Unsigned integers in Java" New topic
Author

Unsigned integers in Java

Zaheer Ahmed
Greenhorn

Joined: Feb 06, 2007
Posts: 22
Hi All!

How can I declare the usigned primitive integers in Java???

I tried the following code:
<code>
public class TestUnsigned {
public static void main(String[] args) {
unsigned int a = 10;
System.out.println(a);
}
}
</code>

But the above code does not compile. It gives "Not a statement" error.

I remember doing something like this... I am not sure whether it was Java or C++. I know that Java is not C++ (Bert) and actually repeated that a couple of times but I am confused here...


Zaheer Ahmed<br />SCJP 5
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

Java doesn't have unsigned ints. If a plain int can't hold a large enough value, and you want to keep the code simple, you can use a long.


[Jess in Action][AskingGoodQuestions]
Zaheer Ahmed
Greenhorn

Joined: Feb 06, 2007
Posts: 22
That I was guessing... Thanks Ernest for clarifying it up...
 
 
subject: Unsigned integers in Java
 
Similar Threads
SCPJ 1.4 - Dan's questons.. not clear
Please explain auto boxing behavior
Building C language's binary protocol strings in Java
Convert small C routine to Java
CRC16 with Polynominal : 0x8408, and Preset CRC : 0x6363