

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
4 messages in net.java.dev.jna.usersRe: AW: [jna-users] Re: Unsigned types| From | Sent On | Attachments |
|---|---|---|
| Timothy Wall | Mar 26, 2009 6:14 am | |
| Novatchkov Hristo | Mar 26, 2009 7:12 am | |
| LYou...@gkservices.com | Mar 26, 2009 7:56 am | |
| Novatchkov Hristo | Mar 27, 2009 2:57 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: AW: [jna-users] Re: Unsigned types | Actions... |
|---|---|---|
| From: | LYou...@gkservices.com (LYou...@gkservices.com) | |
| Date: | Mar 26, 2009 7:56:30 am | |
| List: | net.java.dev.jna.users | |
It won't matter, a byte is a byte 0110 1100 is 0110 1100 no matter what you printf it or code literal it as.
You will be fine.
Levi Yourchuck Senior Programmer Analyst G&K Services Phone: 952 912 5828 www.gkservices.com Enhancing Image & Safety Through Innovation This e-mail and any attachments may contain confidential and privileged information. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this e-mail and destroy any copies. Any dissemination or use of this information by a person other than the intended recipient is unauthorized and may be illegal.
"Novatchkov Hristo" <hris...@univie.ac.at> 03/26/2009 09:12 AM Please respond to use...@jna.dev.java.net
To <use...@jna.dev.java.net> cc
Subject AW: [jna-users] Re: Unsigned types
What I want to do is to call a C function that has an array of bytes as one of the arguments:
//method in C; y is the array of UCHARs bool method(UCHAR x, UCHAR *y)
//method in Java boolean method(byte x, byte [] y)
-----Ursprüngliche Nachricht----- Von: Timothy Wall [mailto:twal...@dev.java.net] Gesendet: Donnerstag, 26. März 2009 14:15 An: use...@jna.dev.java.net Betreff: [jna-users] Re: Threads from yesterday
On Mar 26, 2009, at 4:59 AM, Novatchkov Hristo wrote:
Hi Timothy,
I'm sorry for mentioning the topic again, but is there really no direct way of mapping of C's unsigned types in Java? I would especially need to convert an UCHAR holding a hex value from C in Java, like:
// C code UCHAR test = 0xA1;
// Java code byte test = (byte) 0xA1;
The Java variable, though, has a negative integer value, while the one in C has a positive one. Therefore the code above wouldn't represent a direct mapping. Could you please give me any hints?
You could use a type mapper to convert the byte array into a short or int array in Java, in which case you'd be able to have positive values instead of negative ones, but that still doesn't let you do unsigned 8- bit arithmetic properly without extra work. The easiest thing is to convert the byte into a larger type when you want to look at it as a 0-255 value, e.g.
short value = ((short)byte_array[idx]) & 0xFF;
You still haven't said why you want them to be "unsigned" in Java space. What you want to do with the values will greatly affect the choice of the best representation. Unsigned behavior encompasses much more than simply how a bit pattern is displayed.







