I work in a project where I need to read some values and send through a socket connection. This is the package format I have to create:

I have to read these values (I don’t know what kind of king it should be each value, int or string, etc.): type: type of operation (how to get only 4 bits?) Reserverd: I will write 0 origin: who sends message recipient: who should receive the message algorithm: which algorithm is goona to encrypt the message padding: use it in the encryption algorithm mode: which mode is for encryption
I have to read these values and create this package, which should have only 7 bytes.
How can i do this?
it should be something like this, I think:
byte[] r = new byte[]{
type+reserverd,
origin_1_byte, origin_2_byte,
receiver_1_byte, receiver_2_byte,
algorithm+padding,
mode};
UPDATE:
ByteBuffer buffer = ByteBuffer.allocate(100);
buffer.rewind();
buffer.order(ByteOrder.LITTLE_ENDIAN);
int type = (buffer.get() >> 4) & 0xf;
buffer.rewind();
buffer.put((byte)(type << 4));
System.out.println("type = " + type);
output : 0 (why ?)
Any ideas?