The Boolean values used in a computer program
 

I will start the discussion on "how to represent values inside a computer program with:

  • How to represent the Boolean values inside a computer program

because it is easy and intuitive

 
 

These are all the possible Boolean values are:

    true
    false

Representing (= Encoding) (all) the Boolean values in a computer program

  • Remember that:

      • The computer memory can only store binary numbers !       


  • The commonly used encoding method for Boolean values is:

       Boolean value                Computer code
      --------------------      ---------------------------------
          false          <------>     00000000
          true 	     <------>     00000001
          true 	     <------>  	  00000010
          true	     <------>     00000011
          ...			  ...
    

    (I.e.: ZERO represents false, and everything else represents true)


  • The boolean code is an example of a "committee-based" code
    The "committee" is the designer of the programming language)

Example
 

Python program that illustrates the encoding method:

if 0:
  print("0: true")
else:
  print("0: false")    // <---- does this because 00000000 (=0) == false

if 1:
  print("1: true")     // <---- does this because 00000001 (=1) == true
else:
  print("1: false")

if 4:
  print("4: true")     // <---- does this because 00000100 (=4) == true
else:
  print("4: false") 

DEMO: python3 /home/cs255001/demo/data-type/boolean.py