Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply

Java - Java unsigned integer type for memory addresses

 
Thread Tools Search this Thread
Old 10-17-2005, 09:36 AM   #1
Soeren Meyer-Eppler
 
Posts: n/a
Default Java unsigned integer type for memory addresses

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
  Reply With Quote
Old 10-17-2005, 10:08 AM   #2
Thomas Weidenfeller
 
Posts: n/a
Default Re: Java unsigned integer type for memory addresses

Soeren Meyer-Eppler wrote:
> 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
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/
  Reply With Quote
Old 10-17-2005, 10:33 AM   #3
Roedy Green
 
Posts: n/a
Default Re: Java unsigned integer type for memory addresses

On Mon, 17 Oct 2005 11:36:04 +0200, Soeren Meyer-Eppler
<Soeren.Meyer-> wrote or quoted :

>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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
  Reply With Quote
Old 10-17-2005, 10:35 AM   #4
Roedy Green
 
Posts: n/a
Default Re: Java unsigned integer type for memory addresses

On Mon, 17 Oct 2005 12:08:55 +0200, Thomas Weidenfeller
<> wrote or quoted :

>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
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
  Reply With Quote
Old 10-17-2005, 10:45 AM   #5
Chris Uppal
 
Posts: n/a
Default Re: Java unsigned integer type for memory addresses

Soeren Meyer-Eppler wrote:

> 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


  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cisco 2600 - Inbound NAT translation/Port-forwarding not working Greg Hardware 0 11-20-2008 06:33 PM
Eclipse - Axis2 - Java Webservices Error amanjsingh Software 1 10-09-2007 08:03 AM
Need help on Modelsim VHDL syntax? ASAP:) kaji General Help Related Topics 0 03-14-2007 09:43 PM
Need help on a Modelsim VHDL Syntax? ASAP:) kaji Software 0 03-14-2007 09:43 PM
Need Help on a Modelsim VHDL Syntax....ASAP:) kaji Hardware 0 03-14-2007 09:41 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47