# Boolean Algebra

## Some basic information on doing binary math. Used mainly for microcontroller programming or as a primer for more advance cryptology.

I: Introduction

II: Binary Basics and Booleans

III: Operators

I: Introduction

Boolean Algebra and Bitwise Math is extremely low level mathamatics. Not low

level as in \"2 + 2 = 4\" (or 5 depending on if you\'ve read 1984), but rather

as in the computational level of mathatics the computer does.

I hear a few people voicing the question \"why should I learn this?\"

For 1, it\'s intresting and you learn something, but for those of you who like

purpose, for without purpose we would not exist. These operations can be

used for programming microcontollers and are used in encryption, commonly our

friend Mr. WEP.

II: Binary Basics and Booleans

Okay, if you have NO CLUE what binary is go find a tutorial on that, for the

rest of you a quick review.

Binary: Counting to 10 with only 2 fingers (a loose definition)

Base 10 Base 2(binary)

0 0

1 1

2 10

3 11

4 100

5 101

6 110

7 111

8 1000

9 1001

10 1010

Got it? Questions?

Fine, I\'ll explain a bit(pardon the pun).

Base 10 you count up to ten and carry to the next digit, yes? So base 2 you

count to two and carry, hence no number larger than 1 appears.

Booleans are either a 1 or 0, true or false, on or off, high or

low...depending on how old you are and what you work with. Programmers see

them all the time.

You can think of each bit(0 or 1 in the binary number...ish) as a boolean.

Now...onto the juicy part!

III: Operators

Boolean Algebra and Bitwise Math use a few operators...however its not our

friends(+,-,/,*,%) instead it is &(and), |(or), ^(xor). NOTE: There are

others,but this is enough for now.

Let us explain:

x`

Each operator gives an \"output\" based on 2 \"inputs\" or operands(the numbers

we are using).

& returns a 1 if both are 1\'s and a 0 otherwise

| returns a 1 if either are 1\'s, both are 1\'s and a 0 if neither are 1\'s

^ returns a 1 if both are different and 0 otherwise

These operate bit-by-bit or \"digit-by-digit\" if you prefer...

examples:

1 & 1 = 1

1 & 0 = 0

0 & 0 = 0

1 | 1 = 1

0 | 1 = 1

0 | 0 = 0

1 ^ 1 = 0

1 ^ 0 = 1

0 ^ 0 = 0

Now for a bit bigger

1010 & 0101 = 00003:40 PM 8/8/2006

1010 | 0101 = 1111

1010 ^ 0101 = 1111

XOR and OR look the same here, yes? I\'ll show another

1011 | 1110 = 1111

1111 | 1011 = 1111

1011 ^ 1110 = 0101

0101 ^ 1011 = 1110

Okay, so after a few examples and definitions I hope you are completely

confused, not.

\"Vi Veri Veniversum Vivus Vici. \"

--Samurai

II: Binary Basics and Booleans

III: Operators

I: Introduction

Boolean Algebra and Bitwise Math is extremely low level mathamatics. Not low

level as in \"2 + 2 = 4\" (or 5 depending on if you\'ve read 1984), but rather

as in the computational level of mathatics the computer does.

I hear a few people voicing the question \"why should I learn this?\"

For 1, it\'s intresting and you learn something, but for those of you who like

purpose, for without purpose we would not exist. These operations can be

used for programming microcontollers and are used in encryption, commonly our

friend Mr. WEP.

II: Binary Basics and Booleans

Okay, if you have NO CLUE what binary is go find a tutorial on that, for the

rest of you a quick review.

Binary: Counting to 10 with only 2 fingers (a loose definition)

Base 10 Base 2(binary)

0 0

1 1

2 10

3 11

4 100

5 101

6 110

7 111

8 1000

9 1001

10 1010

Got it? Questions?

Fine, I\'ll explain a bit(pardon the pun).

Base 10 you count up to ten and carry to the next digit, yes? So base 2 you

count to two and carry, hence no number larger than 1 appears.

Booleans are either a 1 or 0, true or false, on or off, high or

low...depending on how old you are and what you work with. Programmers see

them all the time.

You can think of each bit(0 or 1 in the binary number...ish) as a boolean.

Now...onto the juicy part!

III: Operators

Boolean Algebra and Bitwise Math use a few operators...however its not our

friends(+,-,/,*,%) instead it is &(and), |(or), ^(xor). NOTE: There are

others,but this is enough for now.

Let us explain:

x`

Each operator gives an \"output\" based on 2 \"inputs\" or operands(the numbers

we are using).

& returns a 1 if both are 1\'s and a 0 otherwise

| returns a 1 if either are 1\'s, both are 1\'s and a 0 if neither are 1\'s

^ returns a 1 if both are different and 0 otherwise

These operate bit-by-bit or \"digit-by-digit\" if you prefer...

examples:

1 & 1 = 1

1 & 0 = 0

0 & 0 = 0

1 | 1 = 1

0 | 1 = 1

0 | 0 = 0

1 ^ 1 = 0

1 ^ 0 = 1

0 ^ 0 = 0

Now for a bit bigger

1010 & 0101 = 00003:40 PM 8/8/2006

1010 | 0101 = 1111

1010 ^ 0101 = 1111

XOR and OR look the same here, yes? I\'ll show another

1011 | 1110 = 1111

1111 | 1011 = 1111

1011 ^ 1110 = 0101

0101 ^ 1011 = 1110

Okay, so after a few examples and definitions I hope you are completely

confused, not.

\"Vi Veri Veniversum Vivus Vici. \"

--Samurai

Comments

Arto_8000on August 23 2006 - 22:27:48 You forgot the shift operator (<< and >>. Also you could add real example of there use like converting a 0 to 255 digit to hexa (useful for color in HTML). I made a source that mainly use bitwise operator ... It's a good example of there use. http://www.hellboundhackers.org/readcode.php?id=141 For the shift operator it's simple : 1010 << 2 = 101000 and 1010 >> 2 = 10. |

What_A_Legendon August 23 2006 - 23:38:11 would of helped couple months back wen i was studyin it lol but still good article |

only_samuraion August 24 2006 - 04:13:59 haha....arto, i know i didnt include it. this was just for the basics and i mainly just wanted to cover xor. Sorry i didnt write it before What_A_Legend |

minermonkon August 25 2006 - 14:59:25 i reli enjoyed reading this article and learning what it had to offer. good job |

only_samuraion August 25 2006 - 23:29:49 thanks mate...if ya'll have more questions on this stuff or most any programming that there is feel free to pm me and ill try and help out! |

Post Comment

**Sorry.**

You must have completed the challenge

**Basic 1**and have

**100 points**or more, to be able to post.