I have a function that returns the bits of a short (inspired from Converting integer to a bit representation):
bool* bitsToShort(short value) {
bool* bits = new bool[15];
int count = 0;
while(value) {
if (value&1)
bits[count] = 1;
else
bits[count] = 0;
value>>=1;
count++;
}
return bits;
}
How can I do the reverse? Converte the array of bits in the short?
<g>shorthas 15 value bits plus one sign bit does conform, and the code already doesn't deal with negative values properly (perhaps it doesn't need to) for other reasons, so if you ignore the sign bit, 15 bits remain.valueis non-negative and less than 2^16.