Hacker tips: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Hex == See Hex. == Bit manipulation == === Endian swap === For 32-bit: <source lang="bash"> #pseudo code v = (v <<< 24) & 0xff00ff00 | (v <<< 8) & 0x00ff00ff </source>...") |
|||
Line 8: | Line 8: | ||
#pseudo code |
#pseudo code |
||
v = (v <<< 24) & 0xff00ff00 | (v <<< 8) & 0x00ff00ff |
v = (v <<< 24) & 0xff00ff00 | (v <<< 8) & 0x00ff00ff |
||
#pseudo code - variant using 2x same 32-bit constant |
|||
M = 0xff00ff00 |
|||
v = (v <<< 24) & M | ((v & M) <<< 8) |
|||
#pseudo code - variant using 2x smaller 32-bit constant |
|||
M = 0x00ff00ff |
|||
v = ((v & M) <<< 24) | (v <<< 8) & M |
|||
</source> |
</source> |
||
This only requires 2 rotations, 2 bitwise and and 1 bitwise or. |
This only requires 2 rotations, 2 bitwise and and 1 bitwise or. |
Latest revision as of 12:17, 24 January 2020
Hex
See Hex.
Bit manipulation
Endian swap
For 32-bit:
#pseudo code
v = (v <<< 24) & 0xff00ff00 | (v <<< 8) & 0x00ff00ff
#pseudo code - variant using 2x same 32-bit constant
M = 0xff00ff00
v = (v <<< 24) & M | ((v & M) <<< 8)
#pseudo code - variant using 2x smaller 32-bit constant
M = 0x00ff00ff
v = ((v & M) <<< 24) | (v <<< 8) & M
This only requires 2 rotations, 2 bitwise and and 1 bitwise or.