1) Does int have a consistent size across platforms?
2) My IDE doesn't recognize the "unsigned" keyword. Does java have
unsigned int primitives?
I ask because I'm writing methods to set and clear specific bits of an
int array. Or does Java already have these methods built in?
t.i.a
|\/| /| |2 |<
mehaase(at)sas(dot)upenn(dot)edu
Casey Hawthorne - 31 Mar 2004 08:40 GMT
JAVA has a consistent "int" size across platforms which is provided by
the JVM.
JAVA does not have unsigned int primitives - at least up to 1.4.
This is a pain for image processing applications which work on bytes.
You can use shorts -- but waste space.
JAVA has bitwise operators.
Regards,
Casey
Lāʻie Techie - 31 Mar 2004 09:13 GMT
> 1) Does int have a consistent size across platforms? 2) My IDE doesn't
> recognize the "unsigned" keyword. Does java have unsigned int primitives?
[quoted text clipped - 3 lines]
>
> t.i.a
Have a look at java.util.BitSet . BitSet is basically a vector of bits.
It has methods for setting or getting individual bits.
AFAIK, char is the only unsigned primitive in Java. The size of all
primitives are defined in the current specification.
HTH,
La'ie Techie
Roedy Green - 31 Mar 2004 10:23 GMT
>1) Does int have a consistent size across platforms?
>2) My IDE doesn't recognize the "unsigned" keyword. Does java have
>unsigned int primitives?
see http://mindprod.com/jgloss/primitive.html
1) yes, 32 bits.
2) char = unsigned 16-bit short, but alas so unsigned byte, int, long.
see http://mindprod.com/jgloss/unsigned.html
for how to fake it.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.