diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-09-20 23:26:28 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-09-20 23:26:28 +0800 |
| commit | 8dc87e8d58730cd93b1da80f02863398ff8e2dae (patch) | |
| tree | b98138edeb014778aaae51939f379def1152c97f | |
| parent | 1a0f57746d185684551358a35bb6d58b6b575810 (diff) | |
| download | datalab2026-8dc87e8d58730cd93b1da80f02863398ff8e2dae.tar.gz datalab2026-8dc87e8d58730cd93b1da80f02863398ff8e2dae.tar.xz | |
byteSwap
| -rw-r--r-- | bits.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -101,7 +101,19 @@ int logtwo(int v) { * Difficulty: 2 */ int byteSwap(int x, int n, int m) { - return 2; + int ns = (n << 3) ; + int ms = (m << 3); + int nb = (x >> ns) & 0xFF; + int mb = (x >> ms) & 0xFF; + + int mask = ~((0xFF << ns) | (0xFF << ms)); + + x = x & mask; + + x = x | (nb << ms); + x = x | (mb << ns); + + return x; } /* |
