Hello,
I will have an array of 48 byte that will correspond to 48 different
registers. Each register has different fields (eg. register 1 has 1
field of 2 bits, and another field of 6 bits, register 2 is composed of
1 2-bit field and 6 1-bit fields.)
How can I parse the byte array and extract the bits corresponding to
the different fields (and field lengths)
Any suggestions are greatly appreciated.
Andrey Kuznetsov - 26 Jun 2006 17:23 GMT
> I will have an array of 48 byte that will correspond to 48 different
> registers. Each register has different fields (eg. register 1 has 1
[quoted text clipped - 5 lines]
>
> Any suggestions are greatly appreciated.
you need three things to do it:
1) index in byte array
2) bit mask
3) shift amount
class Register {
byte [] values;
int index;
int shift;
int mask;
public int getValue() {
return (values[index] & mask) >> shift ;
}
}
Andrey

Signature
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities