Skip to content

Instantly share code, notes, and snippets.

@CapsAdmin
Created January 20, 2022 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CapsAdmin/64e0392fe6f3d406a607884583fafc49 to your computer and use it in GitHub Desktop.
Save CapsAdmin/64e0392fe6f3d406a607884583fafc49 to your computer and use it in GitHub Desktop.
Synthesizing 10/10 solutions
=======
func swap(x int32) int32 {
return (x & 0xAAAA) >> 1 | (x & 0x5555) << 1
}
=======
func swap(x int32) int32 {
return ((x & 0x0F) << 28) | ((x & 0xF0000000) >> 28)
}
=======
func swap(x int) int {
return ((x & 0x0F) << 4) | ((x & 0xF0) >> 4)
}
=======
func swap(x int) int {
return (x & 0x0f0f0f0f) | ((x & 0x00ff00ff) << 4) | ((x & 0x0000ffff) >> 4)
}
=======
func swap(x int) int {
return ((x & 0x924) >> 1) | ((x & 0x924) << 1)
}
=======
func swap(x int32) int32 {
return (x & 0x3F) | ((x & 0x40) << 1) | ((x & 0x80) >> 1)
}
=======
func swap(x int32) int32 {
return (x & 0xC7) | ((x & 0x80) >> 7) | ((x & 0x01) << 7)
}
=======
func swap(i int32) int32 {
// write your code here
var x, y int32
x = i >> 6
y = i >> 17
x = x & 1
y = y & 1
x = x << 17
y = y << 6
i = i ^ x
i = i ^ y
return i
}
=======
func swap(x int32) int32 {
return (x & 0x60000001) >> 1 | (x & 0x80000080) << 1
}
=======
func swap(a int32) int32 {
// your code goes here
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment