# The Grey Labyrinth is a collection of puzzles, riddles, mind games, paradoxes and other intellectually challenging diversions. Related topics: puzzle games, logic puzzles, lateral thinking puzzles, philosophy, mind benders, brain teasers, word problems, conundrums, 3d puzzles, spatial reasoning, intelligence tests, mathematical diversions, paradoxes, physics problems, reasoning, math, science.

Author Message
Vinny
Promiscuous enough

 Posted: Mon Jul 14, 2003 6:24 pm    Post subject: 1 Got a Computer Science question? Post it here. Somebody will bound to help you out (like that extro dood). I could probably handle the basic programming explanations. For more advanced and hardware stuffs, I'll probably point you toward google (or you might get lucky and extro will enlighten you). [This message has been edited by Vinny (edited 07-16-2003 09:19 PM).]
Vinny
Promiscuous enough

 Posted: Mon Jul 14, 2003 6:51 pm    Post subject: 2 Lesson: Compiling What does it mean to "compile" your code? Here's the gist. Down at the basic level, all computer understands are 0 or 1, or to be more precise, whether a bit is ON or OFF, 2 states, i.e binary code. ?Refletive question 1: Why only 2 states? Why not 3? or 10? or 100? Bonus point to the first with the best answer. Back to compiling. So down at the basic level, the computer fetch and execute these 1s and 0s patterns that tell its hardware,circuits,etc exactly what to do. You can program these exact sequences if you like, but it is quite tedious. Next we have what we called Assembly language, or machine language. These are short symbols that represent a set of 0s and 1s instructions, because a lot of the instructions tend to go together (EXAMPLE: STOR stores a specific bits sequence at a specific memory location). These are a bit easier to program with, but they are still tedious to work with. Imagine 0s and 1s as the actual firing of nerves in your body, and Assembly language as simple "abstract" instructions such as lift your left foot, stick it forward, put it down. Modern computers have automatic built-in hardware to understand these machine languages, to automatically translate them to binary code. Then we have what we called High Level Programming Language. These are your common languages such as C++, Java, Visual Basic, Pascal, COBOL, FORTRAN, etc. See them as actual languages like English, but for computer. This is the easiest way to communicate with the machine and tell it what to do because this is how we think at the concious level. Because every languages have their own specific syntax (just like there are different syntax for English, Spanish, Chinese, etc), they all need a compiler to translate these languages to assembly language so that the machine can understand them. Obviously, each language would have its own compiler. You have a Visual Basic compiler, which understands Visual Basic, a C++ compiler that understands C++, and so on. So in short, compiling your code means to translate it to machine language. ?Refletive question 2: Why do we need Assembly language? Why not just compile straight from the High Level Languages to Binary Code?
Bicho the Inhaler
Daedalian Member

Posted: Mon Jul 14, 2003 6:59 pm    Post subject: 3

 Quote: Imagine 0s and 1s as the actual firing of nerves in your body, and Assembly language as simple "abstract" instructions such as lift your left foot, stick it forward, put it down.
Good analogy
Iced T
Icarian Member

 Posted: Mon Jul 14, 2003 7:08 pm    Post subject: 4 Okay, so,I have this question about my computer-box. See, I plug it into the wall-plug, and then I press the button thingy on the front. But nothing happens, see? Just a little green lite comes on, that's all. And if I put some paper into the little slotty thingy, the little button thingy pops out, but that's all. That's all, man. So, tell me dude, did I get ripped off for buying this computer? The guy down on the corner who sold it to me said that it was top-off-the-liner, which I thought was a good enough thingy, but I can't even find one of those typey thingys that you always see them using on the tv programming. PS. there is a little button called "Turbo", but I am afraid to push that, because I think that it means that Turbo Man is gonna pop out and bust my ass for waking him up.
Vinny
Promiscuous enough

 Posted: Mon Jul 14, 2003 7:15 pm    Post subject: 5 What type and model is your machine? Sounds like one of those original punchcard box. Neato! Are there any external connection points for you to attach devices to? These are the machines that you actually program in binary code in. As I understand it (and somebody help me here cause I am not very familiar with the low level stuff), you punch holes in the card which actually represent 1s, no hole means 0, and you stick it in that slot there. The machine reads in those patterns and stores it exactly as-is in its memory, then you get to play with the bits via some buttons or switches on the machine. What you can do with it depends on the hardware of the machine. If you program it just right, you may get to get the green light to start blinking, sing you a song, and give you the answer to the ultimate question.
Vinny
Promiscuous enough

 Posted: Mon Jul 14, 2003 7:16 pm    Post subject: 6 or maybe you just got ripped off and got sold a toaster. See if a piece of slice bread fits in that slot of your.
casinopete
Emergency Backup Antrax

 Posted: Mon Jul 14, 2003 7:19 pm    Post subject: 7 Q1) note: answer should be taken with at least four grains of salt. The decimal system was chosen by the great philosopher sages of Ancient India and China to represent man's ten fingers, which he uses for toolmaking and writing. Their purpose was to honor man's creativity, his drive for invention, his bold genius in taking the world around him and molding it to his purposes. The decimal system is in every way a celebration of what it is to be man. When man invented computers, he deliberate made a change. No longer, he declared, would the boundless optimism of the decimal system symbolize our race. Instead, the creation of a new numerical system would mark the birth of this new level of control over our environment - binary. We might have hoped that binary arose from similar roots - perhaps a pair of eyes, possibly representing exploration and vision - but sadly, it is not so. In fact, the 102 represents exactly the same thing as the 1010 did - the ten fingers - only now curled into fists. It is acknowledging the inherent brutality of man. Yes, the fathers of computing realized to what purposes their work would be turned. They were not so blindly optimistic as to hope their devices would be used for exploration and invention, for finding and making new worlds. They knew computers would be used to make better weapons, more efficient killing machines. They would make the strong still stronger, and the weak even more defenseless. They would ensure that the world would be guided not by the light of the wise, but by the hand of whoever is ruthless enough to murder freely. So, anyway, Vinny, that's why. fnord.
Vinny
Promiscuous enough

 Posted: Mon Jul 14, 2003 8:01 pm    Post subject: 8 ... yeah ... pete ... that's a good answer ... fnot! That actually brought to mind an interesting concept. Huey and I were playing with our little sister, Cece, who is 5 years old, and we were trying to teach her how to count. For some reason or other, I tried teaching her how to count in binary, and it was very hard for her to grasp the concept. It seems to us that she learn easier on the base-10 system. Huey said something about inate human nature or something, that she doesn't actually see counting and numbers in its purest concept, i.e. how many of something you have against it symbolic representation, but to match symbols with representations, then to build upon those representations. When we get to higher arithmetic, we don't see 100 as actually a hundred of something, just how that symbol works when you apply it to your calculation. e.g. how + 100 would affect the value you have with the first value, etc. I am confusing myself here. Huey then said something about binary not being the lowest counting base. The purest would be unary(?), where you have one single symbol. 1. For one object, 1. Two objects 11. Three objects 111. What a doof.
Bicho the Inhaler
Daedalian Member

 Posted: Mon Jul 14, 2003 8:44 pm    Post subject: 9 Originally posted by casinopete:We might have hoped that binary arose from similar roots - perhaps a pair of eyes, possibly representing exploration and vision - but sadly, it is not so. In fact, the 102 represents exactly the same thing as the 1010 did - the ten fingers - only now curled into fists. It is acknowledging the inherent brutality of man.Are you vying for Pablo's old title, "Master of Hogwash"?
extropalopakettle
No offense, but....

 Posted: Mon Jul 14, 2003 9:53 pm    Post subject: 10 I think the reason we use binary is that it requires the simplest circuitry to implement the operations (such as arithmetic) that we want to implement. Circuits to store base 3 digits would be far more complex than circuits to store base 2 digits (binary digits, or "bits"), and circuits to add numbers made of those base 3 digits would be more complex still.
extropalopakettle
No offense, but....

 Posted: Mon Jul 14, 2003 9:57 pm    Post subject: 11 BTW, not all languages are compiled - some are interpreted. Java isn't compiled to machine language, but to an intermediate language that get's interpreted by a "virtual machine" - a program that understands the intermediate language.
Beartalon
'Party line' kind of guy

 Posted: Mon Jul 14, 2003 11:01 pm    Post subject: 12 Vinny - how would you represent the concept of zero in unary?
Lepton
1:41+ Arse Scratcher

 Posted: Mon Jul 14, 2003 11:02 pm    Post subject: 13 Spell out "Lepton's Bank Account".
Bicho the Inhaler
Daedalian Member

Posted: Mon Jul 14, 2003 11:47 pm    Post subject: 14

Perl is also typically compiled to a bytecode for execution, from what I gather. That may be why Perl interpreters catch syntax errors before beginning execution, since they would need to parse the entire file first.

 Quote: ?Refletive question 2: Why do we need Assembly language? Why not just compile straight from the High Level Languages to Binary Code?

"Why do we need Assembly language?"

Because occasionally (not often, but sometimes) it is desirable for the programmer to interact more directly with the processor. For example, if a certain program (more typically a very small part of a program) needs to be very efficient, the programmer might be able to manually optimize the code in assembly better than the compiler can.

"Why not just compile straight from the High Level Languages to Binary Code?"

(1) A program that translates text (high-level language) into text (assembly language) is probably simpler than one that translates text (high-level language) to binary (machine language). There's already a perfectly good assembler on your operating system, so there's no sense in reinventing the wheel. It is sufficient to write the part that translates the high-level language to assembly and let the assembler take care of the rest.

(2) For every possible executable file, one can write an assembly language program that will assemble to that file, and the translation is very direct, so there's no loss in functionality in creating a compiler that translates into assembly language and then assembles it, vs. a compiler that translates directly into machine code.

(3) It's all about modularity. In practice, it's *much* more desirable to have a program split into separate parts whose communication with one another is limited ("modules") than to have one big monolithic chunk of code. It makes programs easier to debug and to modify (which is basically guaranteed to happen, and successful programs will be modified by many people other than the original programmer(s)). This is a good reason to split compilation into two parts, namely compiling into assembly and assembling.

(4) Have mercy on the people writing the compiler. Their first attempts were probably very buggy. When fixing bugs, a programmer must examine the output of the program. It is much easier to read assembly language, which is text, than to read a binary file. Since they don't actually need write a program to produce binary files (they can use a pre-existing assembler), they don't.

However, if an extremely fast compiler is needed, a compiler that compiles directly into binary code would almost certainly be faster than if it translated to assembly first. I'm sure that for most compiled languages, there are compilers that do this.
CrystyB
Misunderstood Guy

 Posted: Tue Jul 15, 2003 4:43 am    Post subject: 15 Actually, i think because assembler code is clearly more portable than machine code. Some processors might have different bit sequences for instructions, but ultimately they will all correctly interpret ADD ax, bx... Also, to nitpick in my usual style, compiling isn't translating high-level intructions into low-level assembler code. It's just a compilation (put-together) of the already existing code from the PL's library files - they're already in low-level, all that needs to be done is sticking all the used portions of that code in one big 'exe' file... [This message has been edited by CrystyB (edited 07-15-2003 12:49 AM).]
casinopete
Emergency Backup Antrax

 Posted: Tue Jul 15, 2003 1:29 pm    Post subject: 16 Beartalon:
Bicho the Inhaler
Daedalian Member

 Posted: Tue Jul 15, 2003 2:54 pm    Post subject: 17 CrystyB - I admit I don't know enough to argue your first point. My impression was that assembly language was highly unportable across machines, but you may be right that it's more portable than binary files. But your last point isn't really true. It's true that compiling a program does involve linking code from the library, but there is certainly a lot of translating going on. If I write a program in C and compile it, every statement except the calls to library functions will need to be translated into machine-level instructions. Some compilers have an option to stop the compilation process when they get to the assembly part. In gcc it is the -S option. gcc -S somefile.c will translate somefile.c into an assembly language file somefile.s. Any function you write yourself will need to be translated by the compiler and will be visible in somefile.s; only the standard library functions like printf and scanf can be pulled from the library.
Vinny
Promiscuous enough

 Posted: Tue Jul 15, 2003 4:28 pm    Post subject: 18 CrystyB, you should dwell a little more into compilers. They are nifty little programs, with all sort of advanced goodies such as language parser and lexicons and tokens and search trees, wooweee! I only know a little about it from my Comparative Languages course. I wished I have taken a formal compiler class in college. You should if you ever got the chance to.
jesternl
Yankee Doodle Dutchie

 Posted: Wed Jul 16, 2003 8:08 pm    Post subject: 19 And thinking about the binary system, I think it's only 1 and 0, an dnot three or more states, cause it started out with currents. 1 represented current flowing and 0 represented no current flowing. Theere is no inbetween, a little current would still be 1
extropalopakettle
No offense, but....

 Posted: Wed Jul 16, 2003 10:59 pm    Post subject: 20 Well, no, you could have three or more states. 0 is not "no current" (voltage, really), but voltage below a certain threshold, while 1 is voltage above a certain threshold. In practice, the actual voltages used are far enough from the threshold value that errors very rarely occur. So a '0' bit would be represented by a voltage close to 0 volts, while a '1' bit would be represented by a voltage close to 5 volts. 1 volt or 4 volts would still reliably register as '0' and '1' respectively, but somewhere in the middle there's a voltage that you can't really depend on to register one way all the time. But yes, the circuits for three or more discrete states (represented by three or more ranges of voltages) would be much more complex.
extropalopakettle
No offense, but....

 Posted: Thu Jul 17, 2003 1:05 am    Post subject: 21 Of course, the topic has already gone away from computer programming. Taking it further still away, I found a really neat site ( http://www.play-hookey.com/ ) that explains how simple logic gates are built from transistors and such. One ubiquitous type of logic gate is the NAND gate. It's a tiny electronic component that has two inputs and one output, and implements a NAND, or Not-AND. That is, thinking of the inputs, A and B, as booleans (on=1=true, off=0=false), the output is not(A and B). In other words, the output is 1 if and only if at least one input is 0. This logic gate is very common because it's simple, and any other logic functions can be built using just these. You can buy IC chips that have nothing but lot's of NAND gates on them. Then, using NAND gates, you can build things like flip-flops, which are used to store bits. They have a really neat javascript (or something) representation of a J-K flip-flop on this page. There are three inputs: J, K, and the Clock. Blue represents '0' or 'off', red represents '1' or 'on'. Every computer has a clock, which sends out a brief '1' or 'on' pulse repeatedly (at the clock speed of your computer). So if you click the clock input box on the left on and off, and watch the outputs, you'll see ... nothing change. But, if you click one of the J or K inputs to the 'on' state, then the next time you click the clock input on and then off, you'll see that you can permanently change the output. In essence, by looking at the output, you can tell which of the two inputs (J or K) was the last one to be on when some clock pulse went through (unless both were on simultaneously and neither was since, in which case neither was the last one). When J and K are turned off, subsequent clock pulses don't change the output. So, it stores information (exactly one bit of information) indefinitely. From these you can build addressable memory, adders, etc. [This message has been edited by extropalopakettle (edited 07-16-2003 09:12 PM).]
Bicho the Inhaler
Daedalian Member

 Posted: Thu Jul 17, 2003 2:36 am    Post subject: 22 I took a class on those a little over a year ago. The D flip-flop made out of nor latches was my favorite. I think the simpler CMOS D flip-flop has the same behavior, though.
MillerTime
Deceased Extra-Terrestrial Member

 Posted: Sun Jul 27, 2003 12:59 am    Post subject: 23 ewww...logic gates...they cause me pain. we had several lessons on them in my computer science class this year. this guy was trying to teach us how to build half- and full-adders, and how to build more complex gates out of NAND gates, and...bleh. that could just be bad teaching though.
extropalopakettle
No offense, but....

 Posted: Sun Jul 27, 2003 2:14 am    Post subject: 24 When I was an undergraduate in Computer Science, we were required to take a course given by the Physics department (Physics for Computer Science, it was called) that went into the real low level stuff about how transistors work, and what magical properties silicon has (and why it has them) that make it so useful in computer hardware. Little of which I remember. I do remember it as one of the more difficult courses I ever took. I do think when you can go from a basic understanding of what a transistor does (how it does it is another thing), to how they can be used to build a NAND gate and other simple gates, to how to build things like addressable memory and adders and the like, to how to design a simple CPU that executes machine language programs stored in that addressable memory, to a program that translate high level programming languages to that machine language, then, you can really say you understand computers. And throw in an understanding of what an operating system really does, and maybe some theory of computation to round things out.
casinopete
Emergency Backup Antrax

 Posted: Sun Jul 27, 2003 2:25 am    Post subject: 25 In one of my (one semester!) classes, we did just that - started with nand gates, and by the end of the semester had hand-drawn an entire computer, including simple I/O devices. Plus we wrote programs in binary and then assembler for that computer. Simple programs, of course - making a language and writing its compiler and making an OS were for the next (one semester!) class.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year by All usersBeartalonBicho the InhalercasinopeteCrystyBextropalopakettleIced TjesternlLeptonMillerTimeVinny Oldest FirstNewest First
 All times are GMT Page 1 of 1

 Jump to: Select a forum Puzzles and Games----------------Grey Labyrinth PuzzlesVisitor Submitted PuzzlesVisitor GamesMafia Games Miscellaneous----------------Off-TopicVisitor Submitted NewsScience, Art, and CulturePoll Tournaments Administration----------------Grey Labyrinth NewsFeature Requests / Site Problems
You cannot post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum