wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes u_int8_t in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "u_int8_t in java" Watch "u_int8_t in java" New topic
Author

u_int8_t in java

Daniel Botelho
Greenhorn

Joined: Nov 13, 2004
Posts: 6
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

Joined: Oct 30, 2001
Posts: 1970
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.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Daniel Botelho
Greenhorn

Joined: Nov 13, 2004
Posts: 6
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

Joined: Nov 13, 2004
Posts: 6
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: u_int8_t in java
 
Similar Threads
Only fun forwards for fun ...
HTTP request 'GET' example
Conversion help plz!!!
io Problem ..moving the files one directory to another
which is better - array or arraylist??