Become the change you seek in the world. - Gandhi
Wednesday, August 20, 2008
Navigation
Donate
Has this website helped you?
px
If so, please donate a little to help out with hosting costs.
Members Online
Total Online: 46
Web Spiders: 5
Guests Online: 24
Members Online: 22

Registered Members: 34366
Newest Member: boyxunghe
Most Users online: 523
Latest Articles

Logical and Bitwise Operations


advertisement



website security An explanation of logic and bitwise operations, and shifts.

----------------------------------------------
Logical and Bitwise operations
----------------------------------------------

If you write in javascript, php, or a similar language, you're probably familar with conditional statements. Sometimes they deal with conditions, and other times numbers. This will help you understand the different kinds of operators, what's being tested for when you use them, bitwise operations/shifts, and when they might be useful.

Logical Operators
__


AND - used to combine two parts of a conditional statement and check to see if both parts are true
OR - checks to see if at least one part of a statement is true before moving on
XOR - checks to see if only one part of the two returns true
NOT - only returns true if the condition is false

Ok, those are the names, but each one has an actual operator that corresponds.

AND - &&
OR(inclusive) - ||
XOR(exclusive) - ^
NOT - !

Here are a few examples to see how they work

(3==3 && 2 != 1) //true, 3 equals 3 and 2 doesn't equal 1
(7+1==5 || 3 == 4) //false,7+1 is 8, not 5, and 3 doesn't equal 4
(3*3==9 ^ 2!=2) //true, one condition(the first)is true
(6.8 != 6.9) //true, 6.8 doesn't equal 6.9

Bitwise Operations
__


Not only can those operators be used to check conditions, but can also figure calculations with numbers. This is where the bitwise operations come in. What's a bit? Well you should be familliar with binary to understand what's going on here. In a byte, there are 8 bits.

__________________________

| bit | bit | bit | bit | bit | bit | bit | bit |

__________ byte ____________

Example: 3^5=6

So how's it calculated? Well the two numbers the operation is done on are converted to binary. You can get them to binary by going here http://www.yellowpipe.com/yis/tools/encrypter/index.php if you want. So you see that 3 converts to 00110011 and 5 converts to 00110101. Now you're xor'ing these, so you would take the first number from both to start. Remember how only one condition could be true for the whole statement to be true? 1 represents true and 0 represents false you take first number from 00110011 (0) and xor that with the first from 00110101(0) which would be 0. If you were and'ing, they would be the same to get 1. Or would return false. You continue over the whole byte until you have another binary number, which is the answer.

Bitwise shifts
__


Shit left - <<
Shift right - >>

Assembly instructions:

Shift left: SHL
Shift right: SHR


There are shift left's and shift right's of numbers. Again, it has to do with binary.
[number] [way to shift] [ number to shift]

Example: 4<<1;

Get 4 to binary

00110100 then move each number 1 to the left, then convert the result to ascii and you have the answerthe first zero on the left would move to the second from the right and so on to get your answer of 8. Same with the right only you move right.

Why should you need to know these? These shifts and operations are done a lot in assembly and can help you in reverse engineering and analyzing code. They are apart of encryption and making one-way algorithms like MD5 and others. The avalanche effect in encryption is a result of bitwise shifts because the slightest different in bits that make up the byte can make totally different results. Hopefully someone can benefit from this, good luck.

Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 


By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2007- 2008. Since 3rd December 2004.