Bit Manipulation
This post is about Bit Manipulation. I will add more content later.
I tend to forget how negative integers are represented in binary a lot. So here is how:
base 10 base2(using two's complement)
18 00010010
-18 11101110
0010010
+1101101 +1
------------------
01111111 +1
Step1: We first flip the digit of positive 18 = 1101101
0010010
+1101110
------------------
10000000
Step2: and then add 1 to it. 1101101 + 1 = 1101110
1 1101110 is negative 18, the first 1 is the sign.
Masks
I tend to forget how negative integers are represented in binary a lot. So here is how:
base 10 base2(using two's complement)
18 00010010
-18 11101110
0010010
+1101101 +1
------------------
01111111 +1
Step1: We first flip the digit of positive 18 = 1101101
0010010
+1101110
------------------
10000000
Step2: and then add 1 to it. 1101101 + 1 = 1101110
Masks

Comments
Post a Comment