Jump to content

How computers work


la5er

Recommended Posts

If you have ever wanted to learn to program a computer or learn the inner workings of computers this post is for you. It is a simplified version of 4 years of curriculum you would otherwise learn at a university.

First there is computer theory which covers decision trees. As with everything in life when you reach a point or moment you either make a decision to go left or go right. This is how computers work as well. The moment in this case is a parent node and the decisions are the child nodes of that parent node. As a program executes its tree starts to grow branches with each user input and terminates at the last child of which is a leaf in this case.

There are truth tables that are part of computer theory. And they use AND, OR, THEN, and IFF

AND is true if the two inputs on both sides are true otherwise false

OR is false if both inputs are false otherwise true

THEN is true if the first input is true otherwise false

IFF is true if both inputs are true otherwise false

When you append an "N" at the beginning of the four above operations you get the negation or opposite however this is only the case for OR and AND making them NOR and NAND respectively

There are methods computers use to store data that is complex. It stores them in 2 modes: BIN and HEX

BIN is read as such: 10000000 is 1, 01000000 is 2, 00100000 is 4, and so on. Any combination of the 8 different BIN "WORDS" yields the summation. i.e. 11000000 is 3, 10100000 is 5, and so on.

HEX is read a little differently but instead of a WORD of 8 bits it is a WORD of 2 HEX characters ranging from 0 to F with F being a value of 15. So you have 1100 1100 meaning 3 3, 1101 1100 meaning B 3.

You then have data-types of which ALL programs are ultimately broken down into. Strings, Boolean, Integers, Floats, and Doubles.

Strings are things like "Hi, How are you doing".

Booleans are either True or False

Integers are any number without a decimal point in them

Floats are huge numbers that have a high degree of precision that have a decimal point in them.

Doubles are simplified versions of Floats. A difference between a Float and Double can be noted as:

Float: 357373772374166272.6727272782342173215461

Double: 426272.3351

Keep in mind when they can be interchangeable to a degree. There is a range at which they can cover that distinguishes them though.

Next reply to this topic will be about how to write a program. I hope I get a community wide interest as that will open the door for me to post further replies.

Link to comment
Share on other sites

I am a little bit confused. I always thought the LSB is on the right end. Because in C 10000000 is equal to 128, 0100000 to 64 and so on. And 1101 1100 would be DC.

Besides a Computer stores always data in Binary format. Hexadecimal is only a abbreviated form : )

And normally double is the short form for "double float". so it should be

double: 965821431.1285479654

float: 26272.3351

Link to comment
Share on other sites

I am a little bit confused. I always thought the LSB is on the right end. Because in C 10000000 is equal to 128, 0100000 to 64 and so on. And 1101 1100 would be DC.

Besides a Computer stores always data in Binary format. Hexadecimal is only a abbreviated form : )

And normally double is the short form for "double float". so it should be

double: 965821431.1285479654

float: 26272.3351

I wonder if I can say touche on some of your points. However there is big-endian and little-endian. it all depends on what platform the programmers worked on sparc v intel for an example.

At any rate. Lets continue with our lessons.

Lets see how programs are written. Lets take a simple example. A car. Cars have different types of which have their own properties. Hatchback, sedan, pickup, sports-car, etc... These are PUBLIC in scope and are part of the package of car. Lets call these form-factors classes.

Now you wouldnt put a spoiler on a pickup truck if youre a sane person. Nor would you put a 'dualy' on a hatchback, or a rolled-rear pan on the back of a mini-van. These are private properties of their respective class.

Now, how do all these datatypes we talked about earlier? Well all vehicles have wheels. Lets say the wheels in this case are an integer with a value or count assigned to them to make them an integer.

They all have engines as well but the engine comes in a class of its own because they come in twin, v4, etc... They also are 2 stroke or 4 stroke. Can use diesel, unleaded, premium, or hybrid fuels. The cylinder count is an integer that has a value assigned to it, if its on or off being a boolean, in reverse or forward which is also another boolean, the fuel type which is a string describing its type. Etc....

Each vehicle has a paint color(string in this case), How much fuel it can have in its tank(double) i.e. 1.2L, 2.2L,, 4L etc...

Now that we have done all this ground work lets see how the code looks.

Namespace vehicle {

public class engine {

private string fuel

private boolean turnedOn

private boolean direction

private integer cylinders

private double fuel

}

Public class pickup truck {

private engine engine = new engine()

//This is required to be new because you cannot set an engines properties that havent been beyond the blue-print(new) phase

engine.fuel = 34.4

engine.cylinders = 6

engine.turnedOn = false

engine.direction = forward

....(fill in the rest as a challenge)

private string color red

private integer seats = 4

private boolean crewCab = true

private string licensePlate = "12A-5FK"

private turnOn(keyTurned) {

if keyTurned = true

Engine.turnedOn = true

else

Engine.turnedOn = false

}

...... (fill this in with more methods as a challenge)

}

..... (fill the rest of the namespace with other vehicles and properties.

}

The reasoning behind the private and public word modifiers are because you wouldnt want to turn that cars engine on next to you while in your own car would you? Nor would you want to all the sudden go disco on your paint job cause some guy decides to rainbow up his world?

The public word means that you can "buy" a car off the lot with customized(private) features to your hearts content.

Next topic if I receive more interest will be HOW to put a spoiler on the back of a motorcycle! It can be done!

The challenge awaits you, will you take it?

Link to comment
Share on other sites

  • 3 weeks later...

You should probably mention somewhere in that second post that you're talking about the Object Oriented Paradigm. Even more specifically, you might want to mention that you're talking about OOP in what appears to be pseudo-code for Java or C++ (Python for instance is OO but does not have public/private keywords).

You also failed to mention abstraction in the first post which makes me a bit sad.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...
Please Sign In