on master help sign in
Simple implementation of putWord32be
db823ebLennart Kolmodin
@@ -20,3 +20,13 @@ instance BinaryBit Word8 where
20instance BinaryBit Word16 where
20instance BinaryBit Word16 where
21 putBits = putWord16be
21 putBits = putWord16be
22 getBits = getWord16be
22 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
5 , putBool
5 , putBool
6 , putWord8
6 , putWord8
7 , putWord16be
7 , putWord16be
8+ , putWord32be
8 )
9 )
9 where
10 where
10
11
@@ -62,6 +63,17 @@ putWord16be n w
62 t' = fromIntegral (w `shiftL` (8-o'))
63 t' = fromIntegral (w `shiftL` (8-o'))
63 in (S (b `mappend` B.singleton w' `mappend` B.singleton w'') t' o')
64 in (S (b `mappend` B.singleton w' `mappend` B.singleton w'') t' o')
64
65
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+
65flush :: S -> S
77flush :: S -> S
66flush s@(S b w o)
78flush s@(S b w o)
67 | o > 8 = error "flush: offset > 8"
79 | o > 8 = error "flush: offset > 8"