// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import dk.vajhoej.record.FieldType;
import dk.vajhoej.record.Struct;
import dk.vajhoej.record.StructField;
import dk.vajhoej.record.StructWriter;

@Struct
public class ThreeBitFields {
    @StructField(n=0,type=FieldType.BIT,length=6)
    private int value1;
    @StructField(n=1,type=FieldType.BIT,length=6)
    private int value2;
    @StructField(n=2,type=FieldType.BIT,length=4)
    private int value3;
    public int getValue1() {
        return value1;
    }
    public void setValue1(int value1) {
        this.value1 = value1;
    }
    public int getValue2() {
        return value2;
    }
    public void setValue2(int value2) {
        this.value2 = value2;
    }
    public int getValue3() {
        return value3;
    }
    public void setValue3(int value3) {
        this.value3 = value3;
    }
    public static void main(String[] args) throws Exception {
        ThreeBitFields o = new ThreeBitFields();
        o.setValue1(1);
        o.setValue2(3);
        o.setValue3(5);
        StructWriter sw = new StructWriter();
        sw.write(o);
        byte[] b = sw.getBytes();
        for(int i = 0; i < b.length; i++) {
            System.out.printf("%02X", b[i]);
        }
        System.out.println();
    }
}
