Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

u_int8_t in java

 
Daniel Botelho
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to port this c++ code to java:

But here they are using "u_int8_t" char...
How can I do this in java?

Best regards,
Daniel Botelho
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The type to which you refer is not a standard "C" type. It must be a typedef. It looks as if it is probably actually an unsigned 8-bit integer, or byte.

How to represent this in Java depends on what you need to do with the data. I didn't look in detail at your posted code, but perhaps what you really have is text (a zero-terminated array of unsigned 8-bit integers could represent a text string). In that case, java.lang.String might be best. Alternatively, to treat each integer as a separate piece of data, you could use the Java "byte" class (but remember it's signed - that doesn't matter in many operations, but could be crucial in some) or perhaps Java "char" (but remember Java characters are Unicode).

Probably, rather than try to do a direct line-by-line port of the "C" code, you should step back, work out what it does, and re-code in Java.
 
Daniel Botelho
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your quick answering!
Yes, I had already code it in java, but what happens is that some characters are not being well calculated...
This code above should be used to generate a key string form a lock string.
For example I�ve written the following code in java:

For this lock:
passed to the function I receive this key:
, but I should receive this one:
These are the invalid characters:
Position i:19 -> correct='�' (8216) java_code='?' (145)
Position i:24 -> correct='�' (8218) java_code='?' (130)
Position i:41 -> correct='�' (8211) java_code='?' (150)
Position i:45 -> correct='�' (8217) java_code='?' (146)
Position i:48 -> correct='�' (8226) java_code='?' (149)
Position i:58 -> correct='?' (65533) java_code='?' (129)
Position i:64 -> correct='?' (65533) java_code='?' (129)

So I think that this must have something to do with the "char" so I�m trying to use that "u_int8_t" form that c++ code...

Best regards,
Daniel Botelho
 
Daniel Botelho
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is there any class in java that those the same thing that u_int8_t from C?

Best regards,
Daniel Botelho
[ January 11, 2005: Message edited by: Daniel Botelho ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic