darcs patch: Implementation of aton and ntoa outside the IO monad

Lennart Augustsson lennart at augustsson.net
Mon Sep 25 09:00:14 EDT 2006


The VAX is little endian for 32 bit numbers.  It's only 64 bit double  
that are stored with the longwords reversed.
The PDP-11 on the other hand did swap the (16 bit) words when storing  
a (32 bit) long, compared to little endian.

	-- Lennart

On Sep 25, 2006, at 04:47 , Bulat Ziganshin wrote:

> 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 at gmail.com
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries



More information about the Libraries mailing list