Minggu, 22 Maret 2020

SMALL BASIC: LOGIC AND, OR and XOR

Hello SMALL Basic Programmer, welcome.

In this tutorial we will discuss about AND, OR and XOR logic.

You know, small basic is not provide the logic so we will built the function by our self.

So, we will built tree sub procedure:
1. Logic AND code
2. Logic OR code
3. Logic XOR code

Pre-requisite
1. You need to study the truth table of each operation.
2. This program is simply implementing the truth table inside a sub procedure, with simple if condition. So, don't worry. You need to learn how to use elseif. Elseif is how to define another if in the same level if the if.

Facts
1. If you watch carefully, all the IF condition are all use AND keyword, despite OR or XOR operation.
2. Truth table how to memorize it:
Shortcut for OR, if one of any of the input is 1, then the output is 1.
Shortcut for XOR, if both of the input are different, then the output are 1.
Shortcut for AND, if only both of the input are 1, then the output are 1. 


1. Logic AND
x = 1 
y = 1
LogicAND()
TextWindow.WriteLine("The result are: " + result)


Sub LogicAND
  If x = 0 And y = 0 Then
    result = 0
  ElseIf x = 0 and y = 1 then
    result = 0
  elseif x = 1 and y = 0 then
    result = 0
  elseif x = 1 and y = 1 then
    result = 1
  EndIf
EndSub


2. Logic OR
Sub logicOR
    If x = 0 And y = 0 Then
      result = 0
    ElseIf x = 0 and y = 1 then
      result = 1
    elseif x = 1 and y = 0 then
      result = 1
    elseif x = 1 and y = 1 then
      result = 1
    EndIf
  EndSub

3. Logic XOR
Sub logicXOR
    If x = 0 And y = 0 Then
      result = 0
    ElseIf x = 0 and y = 1 then
      result = 1
    elseif x = 1 and y = 0 then
      result = 1
    elseif x = 1 and y = 1 then
      result = 0
    EndIf
  EndSub



Tidak ada komentar:

Posting Komentar