Skip to content

Bitwise Integer Operations

CodingUnit edited this page Dec 7, 2011 · 4 revisions

Bitwise Integer Operations

  • Category: Arithmetic
  • Description: This sample shows how to use the bitwise integer operations
  • Code:
using Nemerle;
using System;
using System.Console;
using System.IO;

    // Operators over integers:
    def x1 = 0xAB7F3456 & 0xFFFF0000;
    def x2 = 0xAB7F3456 | 0xFFFF0000;
    def x3 = 0x12343456 ^ 0xFFFF0000;
    def x4 = 0x1234ABCD << 1;
    def x5 = 0x1234ABCD >> 16;

     // Also over other integral types, e.g. Int64:
    def x6 = 0x0A0A0A0A012343456 & 0x00000000FFFF0000;

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

    // And bytes:
    def x7 = 0x13u & 0x11u;

    // Now print the results:
    WriteLine("x1 = 0x{0:x8}", x1);
    WriteLine("x2 = 0x{0:x8}", x2);
    WriteLine("x3 = 0x{0:x8}", x3);
    WriteLine("x4 = 0x{0:x8}", x4);
    WriteLine("x5 = 0x{0:x8}", x5);
    WriteLine("x6 = 0x{0:x16}", x6);
    WriteLine("x6u = 0x{0:x16}",x6u);
    WriteLine("x7 = 0x{0:x2}", x7);
  • Execution Result:
x1 = 0xab7f0000
x2 = 0xffff3456
x3 = 0xedcb3456
x4 = 0x2469579a
x5 = 0x00001234
x6 = 0x0000000012340000
x6u = 0x0000a0a000000000
x7 = 0x11

[Copyright ©](Terms of use, legal notice)

Clone this wiki locally