package com.safeluck.aykj.utils; public class BitState { public BitState(int b) { this.value = b; this.total = 32; } public BitState(byte b) { this.value = b; this.total = 8; } public BitState(short b) { this.value = b; this.total = 16; } public int total = 32; public int value; public boolean get(int bit) { int pos = bit;//32 - bit; return (this.value >> pos & 1) == 1; } public void set(int pos, boolean state) { //11000110 int move_pos = pos;// 32 - pos; if (state) { this.value = this.value | 1 << move_pos; } else { this.value = this.value & ~(1 << move_pos); } } @Override public String toString() { String str = Integer.toBinaryString(this.value); return getPaddingRightString(str, this.total,"00"); } String getPaddingRightString(String str, int total_len,String padding) { while (str.length() < total_len) { str = str+padding; } return str; } }