Well, that ain't going to work at all well in Java™ because you can't write (char*) and you can't write &v.
Write down the representation of a Java™
int on paper with a pencil (
as Fred always says), and get a large eraser in case anything goes wrong.
Similarly write down a
byte, underneath the
int.
Now you see, you have one number with 32 bits and another with 8 bits.
Now can you work out how to get the right-most 8 bits (bits 0-7 inclusive) out of the 32 bit number? An experienced chap would use the bitwise operators, but the arithmetic operators will do it too.
Now you have an
int representing the right-most 8 bits of your original
int. There remain two things to do.
1: Cast the resultant int to a byte.2: Repeat with the remainder of the int until you have all four bytes out of it. You will probably need to move all the bits 8 places to the right somewhere in this operation.
Remember that an
int might be signed or unsigned in C/C++ and it might have 16 bits or 32, but in Java™ it is always signed (two's complement) and 32 bits. If you know you only need 16 bits, then you will only need two
bytes.