You can’t really “do” computer science without understanding your basic base 2 numbering system.
Converting a binary number (base 2) to a decimal number (base 10) is pretty straight forward if you know your powers of 2:
|Power of 2||$2^7$||$2^6$||$2^5$||$2^4$||$2^3$||$2^2$||$2^1$||$2^0$|
|Decimal Place Value||128||64||32||16||8||4||2||1|
Decimal Value: $128 + 16 + 8 + 4 + 1 = 157$
Binary AND operations work the same way as Boolean AND operations (duh). It combines two binary numbers, 1 bit at a time, AND’ing each bit. A 1 is treated as “True” in Boolean and 0 as False. So anytime there is a 0 in an AND operation the result is always 0. Only 1 $\land$ 1 = 1.
AND’ing anything with a string of 1’s will always be the original binary number:
AND’ing anything with a string of 0’s will always result in a string of 0’s (set to null):
Binary OR operatios also act the same as Boolean OR operations (doi). It acts the opposite of AND: Anytime there is a 1 in an OR operation the result is 1. Only 0 $\lor$ 0 = 0.
OR’ing anything with a string of 1’s will always be a string of 1’s:
OR’ing anything with a string of 0’s will always be the original binary number:
XOR is far more interesting than AND and OR. It only returns 1 if there is a 1 in one of the two operators and not in the other. So if the two bits do not match a 1 is returned and if they do, then a 0 is returned.
XOR’ing anything with a string of 1’s will flip all the bits:
XOR’ing anything with a string of 0’s will always be the original binary number:
One other interesting characteristic of XOR is that it is reversible. So if you take the result of the first XOR and XOR it with the second number in the original operation, you will get the first number:
Bit-level XOR produces exactly the same results as doing addition mod 2:
A left or right shift is a bitwise operation that shifts all the bits in a binary number over however many positions. In order to preserve signedness, the leftmost bit (the sign bit) is replicated rather than being filled with 0’s when doing a left shift. A right shift will just fill in 0’s.
Shifting left by n bits on a signed or unsigned binary number has the effect of multiplying it by $2^n$. Shifting right by n bits on a two’s complement signed binary number has the effect of dividing it by $2^n$, but it always rounds down (towards negative infinity).
A bitwise rotation, also known as a circular shift, either moves the first bit to the last position, shifting all other bits up a position or vice versa. It does not preserve the signedness of the binary number.
Throughout my 10 year career I have worked as a web developer, systems administrator, software engineer, security analyst and now cybersecurity engineer. I currently develop software applications to automate security vulnerability and compliance scanning and reporting for a multinational financial institution.