Reputation: 927
I have the following code in java that I need to convert to c++ to be able to encode unsigned int.
public static int enc_uint32be( int i, byte[] dst, int di ) {
dst[di++] = (byte)((i >> 24) & 0xFF);
dst[di++] = (byte)((i >> 16) & 0xFF);
dst[di++] = (byte)((i >> 8) & 0xFF);
dst[di] = (byte)(i & 0xFF);
return 4;
}
I am a newbie to java. I trust several experts on this forum know both languages - can someone help me with the translation.
Upvotes: 1
Views: 343
Reputation: 131
Actually the code in Java is almost the same in C++ with small modifications:
Upvotes: 1
Reputation: 41252
It depends on the data type that you are planning on using, but if you just change:
byte[] dst
to
unsigned char dst[]
in the function declaration, then it should behave the same (and change the byte usages in the function to unsigned char
as well).
Upvotes: 3