| Author |
Support for Unsigned Integer and Conversion of little Endian to Big Endian.
|
KrishnaPrasad raghavan
Ranch Hand
Joined: Oct 28, 2008
Posts: 46
|
|
Hi,
I have three questions.
a. Regarding Support for Unsigned Integer.
Is the only way for supporting unsigned Integer in Java is to place the value into the next highest Datatype. For instance if I have a int, should I put it in long, will the MSB be zero.
b. Is there any API in Java for converting a value from little Endian to BigEndian since Java Datatypes support Big Endian.
c. Should BigInteger/BigDecimal for storing values while doing Arthematic Operations in Java.
Thanks in Advance
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
KrishnaPrasad raghavan wrote:
I have three questions.
a. Regarding Support for Unsigned Integer.
Is the only way for supporting unsigned Integer in Java is to place the value into the next highest Datatype. For instance if I have a int, should I put it in long, will the MSB be zero.
Next time, I recommend starting different topics -- specific topics seems to stand a better change at getting answered than laundry list topics.
Anyway... I guess the answer is "it depends". If you merely want to have an unsigned int, then yes, it may be best to use a long, and range checking with every operation.
On the other hand, if you want to do 32 bit manipulation. It should be fine to use an int, for bit operations and shifting. You just have to be wary of some sign extension stuff.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
KrishnaPrasad raghavan wrote:
b. Is there any API in Java for converting a value from little Endian to BigEndian since Java Datatypes support Big Endian.
Does it really matter if Java is big or little endian? An int is an int is an int.
The only time that it is important is if you are importing binary data. Text data gets parsed. And once it is imported, it's the right endian, right?
Anyway... try the java.nio.ByteBuffer class.
Henry
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
KrishnaPrasad raghavan wrote:
c. Should BigInteger/BigDecimal for storing values while doing Arthematic Operations in Java.
Not sure what you are asking. Please elaborate the question.
Henry
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12953
|
|
KrishnaPrasad raghavan wrote:b. Is there any API in Java for converting a value from little Endian to BigEndian since Java Datatypes support Big Endian.
I don't know what you mean with "Java Datatypes support Big Endian". You can't say "Java is big endian" or "Java is little endian". In what order the bytes of an int or long are stored in memory depends on the specific implementation of the JVM, there is no requirement in the Java specification that says it has to be either little or big endian. Since there is no way in Java to address memory directly (Java has no pointers), it also doesn't matter how things like int and long are stored in memory - there's no way to see it anyway from your Java program.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Support for Unsigned Integer and Conversion of little Endian to Big Endian.
|
|
|