iotdb icon indicating copy to clipboard operation
iotdb copied to clipboard

Wrong annotation of BytesUtil.getByteN

Open LeiRui opened this issue 3 years ago • 0 comments

Describe the bug Correct usage but wrong annotation of BytesUtil.getByteN.

/**
   * get one bit in input byte. the offset is from low to high and start with 0<br>
   * e.g.<br>
   * data:16(00010000), if offset is 4, return 1(000 "1" 0000) if offset is 7, return 0("0"
   * 0010000).
   *
   * @param data input byte variable
   * @param offset bit offset
   * @return 0/1
   */
  public static int getByteN(byte data, int offset) {
    offset %= 8;
    if (((0xff & data) & (1 << (7 - offset))) != 0) {
      return 1;
    } else {
      return 0;
    }
  }

To Reproduce

byte a = 16;
int tmp = BytesUtils.getByteN(a, 4);

tmp will be 0, not 1 as said in the annotation. Actually for this funciton, the offset is from high to low and start with 0, not from low to high.

LeiRui avatar Oct 05 '22 07:10 LeiRui