[Solved] a pythonic way of doubling consecutive binary bits [closed]

[ad_1] How’s that? from itertools import groupby input_list = [0, 1, 0, 0, 1, 1, 1, 0, 1, 0] results = [0, 0] # First value is zeros, second is ones for key, values in groupby(input_list): results[key] += (2**len(tuple(values))) – 1 assert results == [6,9] [ad_2] solved a pythonic way of doubling consecutive binary bits … Read more

[Solved] Simple logic operation >> &

[ad_1] That code isolates the two bits indicated by the arrows below, and moves them to the two least significant bit positions. vv 11111111111111111111111111111111 original value vv 00000000000000000011111111111111 after >>18 (shift right 18 positions) vv 00000000000000000000000000000011 after & 3 (mask out all but the 0th and 1st bits) This assumes an unsigned value, and no … Read more

[Solved] C/C++ Compressing Integer to Short and Decompressing to Integer [closed]

[ad_1] For 16 bits, there are 216 = 65,536 possible settings. Each setting of bits can represent at most one value. So 16 bits of data can represent only 65,536 values. 32 bits have 232 = 4,294,967,296 possible settings. If your 32-bit data uses more than 65,536 of the possible values that could be represented, … Read more