Skip to main content
gamedev.net
🔒 Locked

[java] Why can't JAVA do unsigned types?

Started by PurpleAmethyst 11 replies 2k views
Original Post
PurpleAmethyst
PurpleAmethyst
I just discovered this yesterday. Why did anyone write a programming language that cant do this. Is there any way to implement something similar? Specifically unsigned bytes.
garazdawi
garazdawi
I''ve never felt that I needed unsigned variables, but maybe that''s just me. Don''t think there is a way to do it though...
garazdawi - 'I put the laughter back in slaughter'
arm
arm
If you're really desperate you could use a char. They are 16bit unsigned integers (in java).

[edited by - arm on January 21, 2004 11:44:51 AM]
PurpleAmethyst
PurpleAmethyst
I think I have to agree with AP. I need it for a compression techinque, I worked out the anding thing already, but thanks for the replies.

garazdawi: I think that you''ll find in things like compression and image prosessing are made easier with unsigned bytes.

overnhet
overnhet
Though I agree that unsigned types can be useful, I fail to see what it would change in the case of compression and image processing. Could you be more specific please ? (no irony nor flames here, real interest)

As of myself, the only case where I explicitly needed an unsigned type was when I add to implement stuff related to a specification (I had therefore no control on the chosen data type). But IMHO this specification was badly designed to begin with : who really needs windows that can be 2^32 units large ?
garazdawi
garazdawi
quote:
Original post by pkelly83
garazdawi: I think that you''ll find in things like compression and image prosessing are made easier with unsigned bytes.

aa, that explains why I never have found it useful. I haven''t done any compression at all as I''m still in my cradle (so to speak)...

garazdawi - 'I put the laughter back in slaughter'
Raghar
Raghar
I would rather have unsigned operators than unsigned types. This will decrease overuse of unsigned types.
I found usability of unsigned types in this i=something;
e=array[ i];
if i could be unsigned then low bound checking could be disabled by default.
signed and unsigned in data compression isn't as important. You'd do just a one more instruction.
i=<<c;
i=&mask63

As for images. You use 32 bit integers anyway, so you could add alfa chanel from separate array. It's easier like this anyway.

I remmember programming language without and operations (applicable on integers). That was severaly bigger problem than lack of MUL in Java.




[edited by - raghar on January 23, 2004 1:28:25 PM]
PurpleAmethyst
PurpleAmethyst
quote:
Original post by overnhet
Though I agree that unsigned types can be useful, I fail to see what it would change in the case of compression and image processing. Could you be more specific please ? (no irony nor flames here, real interest)



Some image formats store the RGB data as 3 or 4 separate bitplanes, it''s easier to load these into unsigned bytes. Usigned bytes are useful in writing Emulators of older hardware or microprocessors. Usigned types save memory as well.

What I was trying to do was compress two values of 0 to 15 in an unsigned byte. That is to store the value 2 and then 10, the byte would be 0xA2 (Java is big-endian). This was to save memory because I''m writing for mobile devices. I have an unsigned byte in JAVA working now anyway.

The argument over whether unsigned types are useful or not could probably turn into a OpenGL vs DirectX or C++ vs JAVA type of thing. IMO unsigned types are useful, others may not use them and I have no problem with this, but they aren''t going to stop me using unsigned types by flaming the thread!

Chaoslab
Chaoslab
All of this seems pointless....

If you want performance bit manipulation then don''t even bother with Java / C++ use some assembly language. Then just wrap it up in an object.

The days of arguing over how to talk to Bare Matel are over, computers are now so fast that it doesn''t matter and they are only getting faster....

:-)

ujhkfkfk
RPGeezus
RPGeezus
Java woes... I''ve had to use unsigned primitives before in Java. If I recall correctly, my solution was:

for an unsigned char, use a short % 0xff
for an unsigned short use an int % 0xffff
for an unsigned int use a long (64 bit in Java) % 0xffffffff;

Slow, yes. Ugly, yes.

Chaoslab: You''ve been misinformed. Some of us fighting with Java are not doing so on PC''s. Our runtime environments are typically slower (~33 Mhz), with limited memory and storage space.

Cheers,
Will

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.