Use bitwise OR to make a number odd
/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Use bitwise OR to make a number odd.
using System;
public class MakeOdd {
public static void Main() {
ushort num;
ushort i;
for(i = 1; i <= 10; i++) {
num = i;
Console.WriteLine("num: " + num);
num = (ushort) (num | 1); // num | 0000 0001
Console.WriteLine("num after turning on bit zero: "
+ num + "\n");
}
}
}
Related examples in the same category