Creatures of X^n heads (part 4/5)


Creatures of X^n heads (part 3/5)

The color system example may seem daunting. But we can also compare the byte with an object popularly perceived as something less “computational”, the flute. A flute has 7 holes on top and 1 hole on the bottom. The flutist blows (equivalent to electrical energy) and decides which holes to plug or unplug. For each note there is then a combination of these 8 holes, some plugged and others uncapped (we assume for simplicity, that the flutist cannot leave a hole partially plugged). When reading a score and playing a melody, you are actually reading a sequence of bytes written in the language of musical scores, interpreting them as finger movements to plug and unplug holes and thus execute your code. Well-written and well-executed code generates the expected melody. In this case, the flutist would be a kind of processor that reads the code and executes it by means of a physical device (the flute) that has the sound as its output.

Example of flute with 8 Boolean variables.

Back to computing, we also work directly with bytes from the ASCII code (American Standard Code for Information Interchange). This encodes a set of 128 signs, from letters of the alphabet, punctuation marks, mathematicians and other particulars that are not printable on the screen. However, 128 signals can be represented by 7 bits, and as we saw earlier, 1 byte has 8 bits, so what happens to this extra bit, if each character uses 8 bits and not just 7? This extra bit is used by the computer itself for different operations depending on the operating system.

We can understand this 1-bit “reserve” as a check digit, similar to the last digits of several identification documents.

Let’s now exemplify the character size of the ASCII code and test if what we type really occupies this space. To do this, open the most basic text editor possible (the Windows Notepad software is a little less basic than we want, but if you don’t have another, it will do). In the case of the Lubuntu system used in this example, we have the LeafPad software, available for similar operating systems derived from Ubuntu (popularly known as Linux). This example will not work with more advanced editors like Office or LibreOffice.

With the editor open write something, count how many characters you used, save the file. Select to see the file properties and verify that the file size will be the number of characters used in bytes. In the example below, I wrote the word “exemplo” in the Leafpad text editor, saved the file with the name x and opened its properties. Note in Total size of files: that its size is 7 bytes. Equivalent to the 7 letters I used in the word example. In this case, these basic editors do not support formatting such as bold, color changes, images, or other common actions in the editing of more refined texts, such as that of this editor himself.

Example file size with 7 characters.

Let’s say that it is in this representation that the magic of programming takes place. Those who program (create or edit software) do not (except for very rare exceptions) in the language of the bits (0’s or 1’s), but (for textual programming languages) in the language of the bytes (0, 1, 2, 3 ,…, 255) represented from the ASCII table. In this case, it is not uncommon to program in software such as Notepad or basic text editors, even though there are specific software to assist this writing, correcting syntax, warning of possible errors in the code, among other tips to assist the programmer in the production of this one. text that will be the code.

But what makes the program work is the so-called compiler. The function of the compiler is similar to the Universal Turing Machine that we explained earlier (not that any compiler is equivalent to a Universal Turing Machine). In this case, it is software instructed to read what we have written and to take action from it. In fact, the compiler interprets our codes according to a sequence of meanings that define a specific programming language, translate it into the language of 0’s and 1’s and make the computer perform the requested actions.

To exemplify this writing, we present the beginning of our own written and commented code in MatLab / Octave (mathematical software) to perform the interpolation of points (connect all points) in the plane by linear splines (line segments) or by cubic splines (curves) of a polynomial of degree 3). In this case, what appears written on a line after # is not considered by the compiler, it is a technique generally used to comment on the code, a way to make it easier for the programmer or other programmers to understand and understand the reasons for each command.

clc # clean the screen

clear all # clears all variables

xfalso=[x1 x2 x3 … xm]; # change here for the x coordinate values

yfalso=[y1 y2 y3 … ym]; # change here for the y coordinate values

nfalso=length(xfalso); # measures the size of xfalso

x(1)=xfalso(nfalso); # assigning the first x the last xfalso

x(nfalso+2)=xfalso(1); # agiving the last x the first xfalso

y(1)=yfalso(nfalso); # assigning the first x the last yfalso

y(nfalso+2)=yfalso(1); # agiving the last x the first yfalso

Below we present a result of its application for a set of previously chosen points. On the left we have the plane points, in the center the interpolation by linear splines and on the right the interpolation by cubic splines.

Example of running the complete code.

Although it seems an exaggeration to present this code here in the text, we consider it an important aspect that is sometimes lacking in texts related to scientific dissemination. Many people may have a misconception about what software is, where it comes from, how they are created… Thus, the code above is in the MatLab / Octave language, it was produced in a notepad and executed from a software that compiles texts / codes in this language. In lines 3 and 4 of the code, we replace the points we want to connect to x and y coordinates. When executing it, we generate the blue dots, the linear spline and the cubic spline.

Creatures of X^n heads (part 5/5)

Back to main page

Who writes the posts?

Deixe um comentário

O seu endereço de e-mail não será publicado.

Skip to content