I don’t know what to call it, which makes googling search difficult.
I have an integer, say 3, and you want to convert it to 11100000, that is, a byte with the value of the integer number of bits set from the most significant bit.
I think this can be done with:
byte result = 0;
for(int i = 8; i > 8 - 3; i--)
result += 2 ^ i;
but is there something faster / more pleasant or, preferably, the standard library included in .net?
source
share