Use bitwise AND to determine if a number is odd
/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Use bitwise AND to determine if a number is odd.
using System;
public class IsOdd {
public static void Main() {
ushort num;
num = 10;
if((num & 1) == 1)
Console.WriteLine("This won't display.");
num = 11;
if((num & 1) == 1)
Console.WriteLine(num + " is odd.");
}
}
Related examples in the same category