This project is read-only.
Bitwise Integer Operations

Category:
Arithmetic
Description: This sample shows how to use the bitwise integer operations
Code:
let Sample4() =
// Operators over integers:
let x1 = 0xAB7F3456 &&& 0xFFFF0000
let x2 = 0xAB7F3456 ||| 0xFFFF0000
let x3 = 0x12343456 ^^^ 0xFFFF0000
let x4 = 0x1234ABCD <<< 1
let x5 = 0x1234ABCD >>> 16

// Also over other integral types, e.g. Int64:
let x6 = 0x0A0A0A0A012343456L &&& 0x00000000FFFF0000L

// Also over other integral types, e.g. unsigned Int64:
let x6u = 0x0A0A0A0A012343456UL &&& 0x0000FFFF00000000UL

// And bytes:
let x7 = 0x13uy &&& 0x11uy

// Now print the results:
printfn "x1 = 0x%08x" x1;
printfn "x2 = 0x%08x" x2;
printfn "x3 = 0x%08x" x3;
printfn "x4 = 0x%08x" x4;
printfn "x5 = 0x%08x" x5;
printfn "x6 = 0x%016x" x6;
printfn "x6u = 0x%016x" x6u;
printfn "x7 = 0x%02x" (int x7)



Execution Result:
x1 = 0xab7f0000
x2 = 0xffff3456
x3 = 0xedcb3456
x4 = 0x2469579a
x5 = 0x00001234
x6 = 0x0000000012340000
x6u = 0x0000a0a000000000
x7 = 0x11

Last edited Sep 14, 2011 at 3:23 AM by ttliu2000, version 1

Comments

No comments yet.