Storing multiple values via bitmask in c#
问题 I'm trying to store four independent 5-bit values (0-31) inside a 32-bit int via bit mask but am having trouble getting the values correct to set and get the individual values from the masked int used for storage. Can anyone help me with this? Edit: Sorry for the external link - here's some JavaScript demonstrating what I'm trying to achieve (but in bitmasks instead of decimal algebra): var s = 0; var v = [31, 6, 23, 31]; //save values s = v[0] + (v[1] * 32) + (v[2] * 1024) + (v[3] * 32768);