#======================================================================
# Author: Isai Damier
# Title: isOdd
# Project: geekviewpoint
# Package: algorithms
#
# Statement:
# Indicate whether the given integer is odd.
#
# Sample Input: 29
# Sample Output: true
#
# Technical Details: The lowest bit of an odd number is 1:
# 1 = 1; 3 = 11; 5 = 101; 7 = 111; 9 = 1001; etc.
# Therefore, x AND 1 should be 1 for all odd numbers.
#======================================================================
def isOdd( x ):
return 1 == ( x & 1 )
import unittest
from algorithms import bitwise as bits
class Test( unittest.TestCase ):
def testIsOdd( self ):
for i in range( 1, 10000, 2 ):
self.assertTrue( bits.isOdd( i ) )
for i in range( 0, 10000, 2 ):
self.assertFalse( bits.isOdd( i ) )