Since March 10, 2003 - Version 2.1
hypothetic.org

MSN Messenger Protocol

Home Page

Forum

About
Contact us

Resources

Research

Documentation
 General
 Notification
 Switchboard
 Client
 Reference

Validate XHTML
Validate CSS
General - bitwise AND
Printable Version

What is bitwise AND?

Bitwise AND is a basic mathematical function like addition or subtraction. However, unlike addition and subtraction, you have to know a bit about binary arithmetic to understand how it works. Understanding how it works is very useful, but its use in the MSN Messenger protocol is so limited that you can get away without it. If you don't want to know how it works, just read "using bitwise AND", below.

How it works

Just as humans use decimal numbers, computers use binary numbers. Decimal numbers are based on powers of ten - one, ten, a hundred, and so on. Binary numbers are based on powers of two - one, two, four, eight, and so on. We would write the number "thirteen" as "13" (i.e. 1 ten plus 3 units), whereas a computer would write it as "1101" (1 eight, plus 1 four, plus 1 unit). Though they look very strange at first, binary numbers are actually much simpler than decimal numbers, and there are more detailed explanations available on-line if you're interested.

You can do all same mathematical operations on binary numbers that you can do on decimal numbers - you can add them, subtract them, multiply and divide them. There are also some operations that you can do on binary numbers but not on decimal numbers - the only one used by MSN Messenger is called "bitwise AND".

Though the name is similar to the "AND" operation used in conditional statements like "if", it's a completely different operation. ANDing two digits together is easy: if both are "1", the result is "1". Otherwise, the result is "0". ANDing two longer numbers means ANDing the digits one column at a time.

This is an example, ANDing "1100" and "1010":

1 1 0 0
1 0 1 0

1 0 0 0

Using bitwise AND

Bitwise AND is one of the simplest operations a computer can do. Every programming language has a built-in bitwise AND function, so you shouldn't attempt to write one yourself. Different programming languages implement bitwise AND in different ways. Some languages implement it as a function such as "and(7, 8)" whereas some implement it as an operator such as "7 AND 8". Check the documentation that comes with your programming environment. This site will use the form "7 AND 8".

Search website:


Copyright©2002-2004 to Mike Mintz.