on master help sign in
Simple implementation of putWord32be
commitdb823eb431707efdc14cfe87b864ad9876305d3d authorLennart Kolmodin <kolmodin@gentoo.org> dateThu 26 Aug 2010, 23:55 (16 years ago) parent2f10d64
2 files changed+22
Bits.hs+10 BitsPut.hs+12
Bits.hs+10
@@ -20,3 +20,13 @@ instance BinaryBit Word8 where
2020instance BinaryBit Word16 where
2121 putBits = putWord16be
2222 getBits = getWord16be
23+
24+instance BinaryBit Word32 where
25+ putBits = putWord32be
26+ getBits = getWord32be
27+
28+{-
29+instance BinaryBit Word64 where
30+ putBits = putWord64be
31+ getBits = getWord64be
32+-}
BitsPut.hs+12
@@ -5,6 +5,7 @@ module BitsPut
55 , putBool
66 , putWord8
77 , putWord16be
8+ , putWord32be
89 )
910 where
1011
@@ -62,6 +63,17 @@ putWord16be n w
6263 t' = fromIntegral (w `shiftL` (8-o'))
6364 in (S (b `mappend` B.singleton w' `mappend` B.singleton w'') t' o')
6465
66+putWord32be :: Int -> Word32 -> BitPut ()
67+putWord32be n w
68+ | n <= 16 = putWord16be n (fromIntegral w)
69+ | otherwise = do
70+ putWord32be (n-16) (w`shiftR`16)
71+ putWord32be 16 (w .&. 0x0000ffff)
72+
73+putWord64be :: Int -> Word64 -> BitPut ()
74+putWord64be n w
75+ | n <= 16 = putWord16be n (fromIntegral w)
76+
6577flush :: S -> S
6678flush s@(S b w o)
6779 | o > 8 = error "flush: offset > 8"