Java unsigned integer type for memory addresses

  • Thread starter Soeren Meyer-Eppler
  • Start date
S

Soeren Meyer-Eppler

Hi,

I'm writing a Java GUI that communicates with a debugger written in C++.
I need to deal with visualizing memory locations and addresses and thus
need to be able to handle 64bit unsigned address values in Java. Since
Java doesn't have any native unsigned types - what's the best way to go
about this?

As an example of what my problem is consider the following case: The C++
debugging client sends me a list of all function entry points in a
program. These are 64bit unsigned address values. My Java GUI receives
them, sorts and displays them. Since Java interprets some of the numbers
as negative the sorting is all screwed up...

So - how do I best represent a 64bit unsigned integer value in Java?

regards,
Sören
 
T

Thomas Weidenfeller

Soeren said:
As an example of what my problem is consider the following case: The C++
debugging client sends me a list of all function entry points in a
program. These are 64bit unsigned address values. My Java GUI receives
them, sorts and displays them. Since Java interprets some of the numbers
as negative the sorting is all screwed up...

If sorting is your only problem, write a Comperator which treats the
Java longs accordingly. If I am not mistaken:

int compare(long a, long b) {
if(a >= 0 && b < 0) {
return -1;
} else if(a < 0 && b >= 0) {
return 1;
} else {
return (int)(a - b);
}
}

You probably also have problems with printing. Just copy one of the many
bin2dec functions which should be around on the net. I am to lazy to
create one from out of head now.
So - how do I best represent a 64bit unsigned integer value in Java?

As 64 bit singed longs. You only get into some trouble if you start to
do some arithmetic with them. Then you can either use BigInteger (takes
much more memory and CPU time), or write your own special arithmetic
methods (which then partly re-implement what is already in BigInteger).

/Thomas
 
R

Roedy Green

Since Java interprets some of the numbers
as negative the sorting is all screwed up...

All you need is an unsigned display method. Long.toHexString should
suffice.
 
R

Roedy Green

As 64 bit singed longs. You only get into some trouble if you start to
do some arithmetic with them. Then you can either use BigInteger (takes
much more memory and CPU time), or write your own special arithmetic
methods (which then partly re-implement what is already in BigInteger).

Unsigned + and - are the same operations as signed. You are surely not
going to multiply your addresses. You might shift them. You have >>
and >>> to deal with signed and unsigned. < works the same for signed
and unsigned.

See http://mindprod.com/jgloss/unsigned.html
 
C

Chris Uppal

Soeren said:
So - how do I best represent a 64bit unsigned integer value in Java?

Actually your problem is not how to represent 64-bit unsigned quantities, so
much as how to represent /addresses/. One approach would be to set up a new
class
MemoryAddress
which contains a 32- or 64-bit number, and which provides whatever behaviour
(formatting, comparison, arithmetic, ...) your application requires.

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top