
Hello Robert, Monday, September 25, 2006, 12:09:13 PM, you wrote:
data ByteOrder = BigEndian | LittleEndian deriving ( Eq, Show, Read )
jfyi: there are (very rare) computers that are not LE nor BE. afaik, VAX was one - it has smth like 1032 byte order, mixing BE in 2-byte words and LE of 2-byte words in 4-byte word (or vice versa, i'm not sure)
flipEndian :: Integral a => a -> a flipEndian = wordConcat . reverse . toWord8s
a bit faster: flipEndian n = let w1 = (n ) .&. 0xff w2 = (n >># 8) .&. 0xff w3 = (n >># 16) .&. 0xff w4 = (n >># 24) in (w1 <<# 24) .|. (w2 <<# 16) .|. (w3 <<# 8) .|. w4 #ifdef __GLASGOW_HASKELL__ (I# a) <<# (I# b) = (I# (a `iShiftL#` b)) (I# a) >># (I# b) = (I# (a `uncheckedIShiftRL#` b)) #else /* ! __GLASGOW_HASKELL__ */ a <<# b = a `shiftL` b a >># b = a `shiftR` b #endif /* ! __GLASGOW_HASKELL__ */ -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com