I'm not exactly sure what you mean. Because if your type is uint32, the (>>>) operator should work on it.

1
2
3
4
5
6
7
8
9
10
11
12
let u = (256u >>> 1)

let ui = (-256 |> abs |> uint32 >>> 1)

let i = (-256 |> uint32 >>> 1)

printfn "%d" u // prints 128

printfn "%d" ui // prints 128

printfn "%d" i // prints 2147483520
By on 4/16/2009 4:41 PM ()

You cast to an unsigned type and then use the right-shift operator (>>>), just like in C. For example:

1
(uint32 x)  >>> 31
By on 4/16/2009 8:20 AM ()

You cast to an unsigned type and then use the right-shift operator (>>>), just like in C. For example:

1
(uint32 x)  >>> 31

Trick question! That answer don't work, because the cast does a sign extend:

1
2
3
4
let inline (>>>>) x n = (uint32 x)  >>> n;;
> -1s >>>> 8;;
val it : uint32 = 16777215u

Looks like an oversight in the F# core.

By on 4/16/2009 9:07 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper