Posts

Showing posts from June, 2016

2023-09-13, Wednesday, Cloudy

新工上遇上了挫折。寫好的東西達不到標準需要別人執手尾了。雖然同事說沒關係,但反應了自己的不足。有時反省自己為何做事總是不好,為何別人有留意或想到的事情自己總是忽略。現在覺得是自己天生的思考模式問題,可能看多少書都沒用。或者自己應該更適合做地盤呢類工作,而唔係IT。

Something about bit operation

One day I was thinking of how to handle an array of bits so I can use it to mark some information of another array. After checking below thread final I've made my own class to handle it. As I am not a very good coder I may have made careless mistake but still want to put it here for my future reference and whoever passes by here please do leave me some comment about it so I can improve myself. /**  * Create a simple class containing an array of bits.  *  * @author Whelan Chan  *  */ public class BitArray{     private long bitX64[] = null;     private final static int BIT_SIZE = 64;       public BitArray(int size) {         bitX64 = new long[size / BIT_SIZE + (size % BIT_SIZE == 0 ? 0 : 1)];     }     public boolean getBit(int pos) {         return ((bitX64[pos / BIT_SIZE] >> pos & 1l) == 1l);     }     public void setBit(int pos, boolean b) {         long b8 = bitX64[pos / BIT_SIZE];         long posBit = (long) (1l << (pos % BIT_SIZE));