
9 Dec
2008
9 Dec
'08
6:30 a.m.
Hello, I'm trying to do some bit arithmetic. Here's the function:
import Data.Bits import Data.Word
g :: Word32 -> [Word32] g x = [(x `shiftR` 24) .&. 0xFF, (x `shiftR` 16) .&. 0xFF, (x `shiftR` 8) .&. 0xFF, x .&. 0xFF]
This function should give bytes for the given number, like this: g 255 -> [0,0,0,255] g 256 -> [0,0,1,255] g 65535 -> [0,0,255,255] In reality, I get very strange answers. Can anybody help me please? Regards, Artyom Shalkhakov.