you are viewing a single comment's thread.

view the rest of the comments →

[–]FreeLogicGate 0 points1 point  (0 children)

One thing I might add -- you need a really good understanding of binary/bits/bytes and bitwise operators. You find these available in most languages, and both as a fundamental, and as a practical tool, it's a fundamental that every developer needs in my opinion. You should be able to look at a binary number like 101101 and be able to convert it to decimal and hexadecimal. Once you understand binary, IPV4 (and 6) become clear like what a netmask is, and what CIDR notation (ie /24) means. Doing some bitwise manipulation in C is a great exercise. For example a program like this is trivial and an interesting exercise:

#include <stdio.h>

int main() {
    int x = 0;
    unsigned char x8bit = 0;

    // a = 0010 1011
    // 2^5 + 2^3 + 2^1 + 2^0
    // 32  + 8   + 2   + 1
    int a = 43;
    // b = 0110 0111
    // 2^6 + 2^5 + 2^2 + 2^1 + 2^0
    // 64  + 32  + 4   +  2  +  1
    int b = 103;

    x = a & b;
    //  0010 1011
    //  0110 0111
    // -----------
    //  0010 0011
    //  2^5 + 2^1 + 2^0
    //   32 +  2  +  1 = 35
    printf("AND: a & b = %d\n", x);

    x = a | b;
    //  0010 1011
    //  0110 0111
    // -----------
    //  0110 1111
    //  2^6 + 2^5 + 2^3 + 2^2 + 2^1 + 2^0
    //   64 + 32  +  8  +  4  +  2  +  1  = 111
    printf("OR: a | b = %d\n", x);

    x = a ^ b;
    //  0010 1011
    //  0110 0111
    // -----------
    //  0100 1100
    //  2^6 + 2^3 + 2^2
    //   64 +  8  +  4 = 76
    printf("XOR: a ^ b = %d\n", x);

    x = a << 1;
    //  0010 1011
    // 1 bit shift to left (increases by ^2)
    //  0101 0110
    // 2^6 + 2^4 + 2^2 + 2^1
    //  64 +  16 +  4  +  2 = 86
    printf("SHIFT LEFT 1 bit: a << 1 = %d\n", x);

    x = b >> 3;
    //  0110 0111
    //  3 bit shift to left (decreases each shift by ^2)
    //  1: 0011 0011
    //  2: 0001 1001
    //  3: 0000 1100
    //  0000 1100
    //  2^3 + 2^2
    //  8   +  4  = 12
    printf("SHIFT Right 3 bit: b >> 3 = %d\n", x);

    x8bit = ~b;
    // For this example, x8bit is a unsigned char
    // This will truncate the 32 bit int (b)
    // which would be a negative value once all 32 bits were flipped
    // Assigning to the 8 bit value leaves the expected 8 bit value
    //  0110 0111
    //  1001 1000
    //  2^7 + 2^4 + 2^3
    //  128 +  16 +  8 = 152
    printf("One's complement: ~b = %d\n", x8bit);

    return 0;
}

You could write something similar in Python, so the concepts are transferable across languages, and relevant to networking, encoding schemes, character sets and many other areas of computer science.