News for hackers. Stuff that matters.
Re:A Bit Overcomplicated by edflsafoiewq on Thursday August 05, 2021 @02:18PM (#28077483)
The usual reason is packing/unpacking bitfields.

To extract the hours/minutes/seconds from a DOS timestamp

  hour = (timestamp >> 11) & 0x1f
  min = (timestamp >> 5) & 0x3f
  sec = (timestamp & 0x1f) * 2
To check if a byte is a UTF-8 continuation byte

  (x >> 6) == 0b10
To pack 5-bit r, g, b values into a 16-bit integer

  (uint16)r | ((uint16)g << 5) | ((uint16)b << 10)
To swap the bytes of a uint32 (little endian <-> big endian conversion)

  (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24)

There are no comments on this comment yet.