C to Java translation
-
Hi, is there a reliable tool which can convert completely a C code to Java. C code contains only bit operations such AND, OR ... XOR, addition, subtraction and like and is not dependent on particular library. The tool should convert the code completely i.e. without my intervention after translation.
-
Hi, is there a reliable tool which can convert completely a C code to Java. C code contains only bit operations such AND, OR ... XOR, addition, subtraction and like and is not dependent on particular library. The tool should convert the code completely i.e. without my intervention after translation.
Kujtim Hyseni wrote:
The tool should convert the code completely i.e. without my intervention after translation.
It is unlikely that any tool is capable of doing that since there are enough subtle differences in the languages, and coding style to confuse it. If you want a selection of tools that you can try for yourself then Google is your friend.
Veni, vidi, abiit domum
-
Hi, is there a reliable tool which can convert completely a C code to Java. C code contains only bit operations such AND, OR ... XOR, addition, subtraction and like and is not dependent on particular library. The tool should convert the code completely i.e. without my intervention after translation.
When I translate the C code to C# it works fine because in both C and C# there is unsigned 8 bit integer type "byte" (values from 0 to 255) while in Java "byte" is signed 8 bit integer (values from -128 to 127). What operations might have effect when signed used instead of unsigned?
-
Hi, is there a reliable tool which can convert completely a C code to Java. C code contains only bit operations such AND, OR ... XOR, addition, subtraction and like and is not dependent on particular library. The tool should convert the code completely i.e. without my intervention after translation.
You can't expect 100% automatic conversion. Even commercial products offers only 95-99% conversion. In Google you could find few free converters. Ex. C To Java Converter[^] There's a better way if you have more time & resources. Code Rewrite[^]
thatraja
Code converters | Education Needed No thanks, I am all stocked up. - Luc Pattyn When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute
-
When I translate the C code to C# it works fine because in both C and C# there is unsigned 8 bit integer type "byte" (values from 0 to 255) while in Java "byte" is signed 8 bit integer (values from -128 to 127). What operations might have effect when signed used instead of unsigned?
-
If you use arithmetic operations on them then you will get incorrect results.
Veni, vidi, abiit domum
How do you mean, can you explain me more ?
-
How do you mean, can you explain me more ?
Try this code:
public static void main(String\[\] args) throws Exception { byte b1 = (byte)129; byte b2 = 4; byte b3 = (byte)(b1 + b2); System.out.println("b1 is: " + b1); System.out.println("b2 is: " + b2); System.out.println("b3 is: " + b3);
If the
byte
values wereunsigned
you would expect the answer to be133
, but in fact you will get-123
, since the 'real' value of b1 is, as you see,-127
.Veni, vidi, abiit domum
-
Try this code:
public static void main(String\[\] args) throws Exception { byte b1 = (byte)129; byte b2 = 4; byte b3 = (byte)(b1 + b2); System.out.println("b1 is: " + b1); System.out.println("b2 is: " + b2); System.out.println("b3 is: " + b3);
If the
byte
values wereunsigned
you would expect the answer to be133
, but in fact you will get-123
, since the 'real' value of b1 is, as you see,-127
.Veni, vidi, abiit domum
Yes, but I am receiving un-correlated values, how to get 133 instead of -123 - I mean what modifications or things I have to do at the end?
-
Hi, is there a reliable tool which can convert completely a C code to Java. C code contains only bit operations such AND, OR ... XOR, addition, subtraction and like and is not dependent on particular library. The tool should convert the code completely i.e. without my intervention after translation.
-
Yes, but I am receiving un-correlated values, how to get 133 instead of -123 - I mean what modifications or things I have to do at the end?
You have to get the value as an integer and then mask off the low order 8 bits, to make it into an unsigned value, like this:
public static void main(String\[\] args) throws Exception { byte b1 = (byte)129; // b1 is the original unsigned value, which takes the full 8 bits byte b2 = 4; // b2 is a normal value int i1 = b1; // make b1 an integer int i2 = i1 & 0xFF; // mask off all but the low order 8 bits, i.e. the original byte value int i3 = i2 + b2; // add the two original values together System.out.println("i1 is: " + i1); // the negative byte value, same as b1 System.out.println("i2 is: " + i2); // the unsigned value System.out.println("i3 is: " + i3); // the sum of the two numbers }
[edit]Fixed typo; I meant low order 8 bits.[/edit]
Veni, vidi, abiit domum