A Crash Course in Computer Science Basics

Sit down and shut up, because I’m gonna learn you some software.

All example code is written in Groovy, because it’s an underrated language that deserves more respect.

Alright, so the main thing you need to understand about computers is that everything is whole numbers. Numbers are numbers.

0b1000_1010 == 0x8a == 138
// binary  hexadecimal  decimal
// |            |            \
// What your     \            What we humans usually read.
// computer sees. \
//                 A nice compromise that's easy for
//                 humans to understand, but easily
//                 translated to binary for computers.

Letters are numbers.

(int)'b' == 98 // (int) means "Interpret this value as an integer instead."

Less common characters are represented by bigger numbers.

(int)'…' == 8230

“Strings” (words, sentences, etc.) are just arrays of characters, which are in turn numbers.

(int[])"This is a string." == [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103, 46]
// "int[]" means "Array ([]) of integers (int)."

Hey, can you tell me the time? Sure, it’s this long-ass number, the Unix timestamp, the number of seconds since midnight, January 1, 1970.

Even the values for each individual pixel on your screen – how bright each color has to be, and the ratios between them – are represented by six-digit hexadecimal numbers. My favorite color, for example, is #138b38.

This color right here.

So then how do you code? You tell a computer what to do with its numbers, and how to interpret them.

static void main(String[] args) {  // Main function, what actually gets run when you start the program.
    println("This gets printed to the screen.")
    int c = 5;  // "int" means integer, a whole number.
                // This sets the value 'c' equal to five.
    while (c > 0) { // While the value of 'c' is still positive...
        println("Current number is " + c);  // ...print c's value...
        c--; // ...decrement 'c' (subtract 1)...
    }        // ...and restart the loop. 
    // Boom, you just learned how "while" loops work.

This code will output:

This gets printed to the screen.

Now obviously there’s a lot more to coding and computer science than this, but a pretty good start is to understand that everything is represented in the form of numbers. That’s why CS has historically been treated as a sort of math major offshoot.

I’ll clarify things a bit more in future articles/videos. Until then!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s