Last active
January 26, 2020 17:27
-
-
Save hadronized/99df1626d8709d55b6526e9c19d154e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
toBin8 :: Int8 -> Integer | |
toBin8 x = | |
y .&. 1 | |
+ (y `shiftR` 1 .&. 1) * 10 | |
+ (y `shiftR` 2 .&. 1) * 100 | |
+ (y `shiftR` 3 .&. 1) * 1000 | |
+ (y `shiftR` 4 .&. 1) * 10000 | |
+ (y `shiftR` 5 .&. 1) * 100000 | |
+ (y `shiftR` 6 .&. 1) * 1000000 | |
+ (y `shiftR` 7 .&. 1) * 10000000 | |
where y = fromIntegral x | |
toBin16 x = (toBin8 (fromIntegral $ x `shiftR` 8) * 100000000) + toBin8 (fromIntegral $ x .&. 0xFF) | |
toBin32 x = (toBin16 (fromIntegral $ x `shiftR` 16) * 10000000000000000) + toBin16 (fromIntegral $ x .&. 0xFFFF) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment