Binary, hexadecimal and octal integers are the most common number bases generally used in computer science and computer science related fields.
Have you tried debugging a compiled C program, you'd either be looking at plain hexadecimals or Assembly instructions alongside the hexadecimal equivalent. Some people are so technical-savvy that they know what they are doing by just staring at hexadecimal, alternatively called an hexdump. Some will only understand what the hexadecimal is doing when they see the equivalent Assembly code. I won't lie, either way some don't know what is happening—Assembly is crazy it can make you too 😂😂.
The fun fact is; you don't need to debug a compiled C program or do reverse engineering before you need to understand these three beautiful number bases. You could just be a random programmer working Binary Manipulation like bit masks, shifting, turning on and off bits, to come to the realization that you need to know how these number systems work.
Binary integers like other digits are written from left to right—the most significant bit to least significant bit.
10001011 -> 139 ^ ^ ^ ^ ^ least significant bit most significant bit
I converted that binary number to it's decimal, in less than 10sec, just as I was writing, merely looking at it
You should know this if you've ever worked with binary numbers
The power of
0 - 8 (1bit - 9bits) that is,
1 - 256, may be enough for you to know. At least for basic binary calculations.
I guess you have noticed a pattern already. Yes, let's assume 20 as ground state. Every binary integer, that has at least a bit turned on, has this in them. So there is a 20 in 2, 4, 8, ..., 2n.
Every number except zero has a
1ready state in its most significant bit, since every number contains a 20.
The number of zeros
0that follow the
1from the most significant bit, is the power of 2. So 21 = 102 = 2.
The 1 from the most significant bit is owned by 2^0 The following 0 is accounted for, by the power on 2
The number of bits in a 2n number is
n + 1, because the possible outcome of
nnumber of bits ranges from 0 to 2n-1, not 1 to 2n, for all unsigned integers.
Let's pick some digits to make a decimal integer, say
From our table, let's pick the closest number to this,
8, 23 = 10002.
We have a variable
temp = 1000, in binary. The remainder is
The closest number to
5from the table is
Since the number is
5, we could simply say the remainder is
1and add it to 1002, which gives 1012.
Alternatively, you could turn on the first turned-off bit from the least significant bit (rightmost side), and turn off the bit to the right of the one you turned on, if there is any.
10000 = 16 To add 1, turn on the rightmost 0, that is change it to 1 To give 10001 = 17 10001 = 17 To add 1, turn on the rightmost 0, and turn off the 1 closest to the 0 you turned on. To give 10010 = 18 See the pattern: 10000 = 16 10 = 2 10000 + 10 = 10010 = 18.
So we add
5 = 101to
8 = 1000and we get
13 = 1101
Let's pick some bits to make a binary integer, say
Break the bits from the rightmost side, and replace whichever bit you have taken with
0in the original number
11 = 3,
remainder = 10010000
10000 = 16,
remainder = 10000000
10000000 = 128,
remainder = 0
Add all: 128 + 16 + 3 = 147.
Something you need to know again, is the odd end of
n number of bits, that is the 2n-1. Here is another table for that.
|Factor - 1||Decimal||Binary|
|21 - 1||1||1|
|22 - 1||3||11|
|23 - 1||7||111|
|24 - 1||15||1111|
|25 - 1||31||11111|
|26 - 1||63||111111|
|27 - 1||127||1111111|
|28 - 1||255||11111111|
|29 - 1||511||111111111|
|210 - 1||1023||1111111111|
|211 - 1||2047||11111111111|
|212 - 1||4095||111111111111|
At least you should know this from 1 - 255.
I hope you enjoyed this 😍. You can fav it here and follow me on twitter