![]() Unsigned char inByte3 = (toReverse & 0xFF000000) > 24 Unsigned char inByte2 = (toReverse & 0xFF0000) > 16 Unsigned char inByte1 = (toReverse & 0xFF00) > 8 Unsigned char inByte0 = (toReverse & 0xFF) If you want to do this on a 32-bit int, just reverse the bits in each byte, and reverse the order of the bytes. Int s = sizeof(v) * CHAR_BIT - 1 // extra shift needed at endįaster (64-bit processor) unsigned char b // reverse this (8-bit) byteī = (b * 0x0202020202ULL & 0x010884422010ULL) % 1023 Unsigned int r = v & 1 // r will be reversed bits of v first get LSB of v Simple unsigned int v // input bits to be reversed ![]() ![]() You can extend this idea to 64-bit ints, or trade off memory for speed (assuming your L1 Data Cache is large enough), and reverse 16 bits at a time with a 64K-entry lookup table. Unsigned char * q = (unsigned char *) &c Unsigned char * p = (unsigned char *) &v Low Memory (32-bit int, 32-bit machine)(from here): unsigned int NOTE: All algorithms below are in C, but should be portable to your language of choice (just don't look at me when they're not as fast :) Options
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |