bitwise & doesn't work with bytes in kotlin

前端 未结 2 1120
渐次进展
渐次进展 2020-12-16 10:33

I\'m trying to write kotlin code like:

for (byte b : hash)  
     stringBuilder.append(String.format(\"%02x\", b&0xff));

but I have not

2条回答
  •  忘掉有多难
    2020-12-16 11:22

    Bitwise "and" of any byte-value and 0xff will always return the original value.

    It is simple to see this if you draw the bits in a diagram:

    00101010   42
    11111111   and 0xff
    --------
    00101010   gives 42
    

提交回复
热议问题