What is Glitch.com?

Glitch.com is a website that features an online code editor with which you can create, host and deploy Node.js applications and static websites.

You write the code online and that’s it! The deployment is instantaneous!

And yes, you can also use Express (the famous Node.js web application framework).

In the free tier, your code is public, so you can use this tier for open source projects and as a learning tool.

With Glitch.com, you do not have to install Node.js on your computer to serve a Node.js application. You only need your web browser to go to Glitch.com, write code and view the results.

Glitch.com‘s landing page has a lot of great ideas and examples for Node.js applications you can create and host on Glitch.com.

Glitch.com pricing is at the following link: https://glitch.com/forplatforms/.

A great article that uses Glitch.com to host and run the article’s featured code is the following: How to set up a database if you’re a front-end developer.

Advertisements
Posted in Web design

About racism

People call me racist. That may or may not be beside the point of this blog post.

We, humans, are designed to be racist. I do not like this, though, and this is one of the reasons that made me reach the conclusion that the human kind should not exist anymore. I do not think racism, discrimination, differentiation are just or moral. I want all people to be equal. All people are different, but that should not stop them from being equal.

I find it absurd to judge someone based on their skin color, sexual orientation, beauty, health, age, and so on.

But, as I previously wrote, we are designed to be racist. That is how we evolve. Again, I do not like it. But our designer is to blame, not us. What a bad, unjust, racist creation did she make: us. Yes, we should vanish from the face of the Universe.

I walk on the street and I see cafés. This is what I ALWAYS observe concerning cafés: If a woman is young and/or beautiful, she will be a waitress. If she is old and/or ugly, she will be a cleaning lady. ALWAYS. Let me make a mental experiment: Suppose I go to a café owner and confront her about this discrimination. Do you know what she will say? Well, let me guess. She will probably say that if she did otherwise, hiring the beautiful as cleaning persons and the ugly as waitresses, customers would not prefer going to this café. She would lose customers and end up going out of business.

And I am the racist.

Our creator programmed us to seek our sexual partner, our spouse, our companion, our friends, based on discrimination. As far as our spouse is concerned, we are programmed to pick and choose. If not for that, the human race would degenerate, instead of evolve. We choose good looking sexual partners to produce healthy children. This is our genetic predisposition. This is how humanity is programmed. Actually, this is how all species are programmed. And this is how nature works. Survival of the fittest and all that. Totally immoral.

Change is the only constant, as a wise man once said. And I take it from there: Those who adapt, survive. Those who do not, perish.

And I am the racist.

Anyone who ever had a friend, a spouse, a sexual partner is a racist. If you are married or have fallen in love, you are being racist. Only monks cannot be considered to be racist. All others pick and choose, discriminating people based on their looks, height, age, wealth and so on, in order to mate with them.

And I am the racist.

Or not. The point of this blog post is to prove that all of us are racists. Except monks. And monks are the only humans I respect.

Posted in Science

How to install Lands of Lore Guardians of Destiny

Lands of Lore Guardians of Destiny is a PC game from Westwood Studios, Inc. that was released in 1997 for DOS and Windows 95. I purchased a copy in 1998, if I remember the year correctly. It contained  4 CD-ROMs.

As far as I know, you should buy a copy of the game in order to play it. It is not free. The following assumes that you own a copy of the game.

If you want to learn more about the game and you want to download it for various reasons (for example any one of the CD-ROMs is scratched and no longer working), you can visit any of the following two links.

If you download the game from any one of the two links above, I will show you what to do next in order to install it in a modern version of Windows.

Any of the two links above will allow you to download the following two files:

  • Lands_of_Lore_II-THEiSOZONE.7z.001
  • Lands_of_Lore_II-THEiSOZONE.7z.002

These are zipped files in the 7z (7-Zip) format and you should already have a file archiver utility in your PC (like 7-Zip or WinRAR) in order to unzip them. Right-click on the first file, choose the file archiver utility you want from the context menu and it will unzip both files, on after the other, without you having to point the second file to it.

After unzipping the two files, a folder structure will emerge, comprised of the following folders:

  • CD1
  • CD2
  • CD3
  • CD4
  • Manual
  • Patch
  • Scans

Each of the first four folders contains one of the CD-ROMs of the game, in an mdf/mds format. This format is used in order to contain the content of one CD-ROM disc. The .mdf file has a large size and the .mds file has a small size.

You can use a utility like Alcohol 52%, Alcohol 120%, or PowerISO (or any other utility like them) to create virtual drive letters and drives, then mount these .mdf/.mds files and then install and run the game from the virtual drives.

In a modern Windows OS, the game may have trouble running, becuse it was developed for older Windows OS’s. To overcome any problems and to be able to run it on newer Windows OS’s, I recommend downloading an installing DOSBox, which is an x86 emulator with DOS. I recommend installing the game in DOSBox and running it from there. Not only that, but I also recommend to extract the content of the CD-ROMs (using Alcohol or PowerISO by mounting them first or simply extracting the contents, depending on the utility) and then use DOSBox’s ability to mount them as virtual drives.

In the rest of this blog post, I will show you how you can use DOSBox as a utility, like Alcohol or PowerISO, in order to mount a folder hierarchy as a virtual drive and then install and run the program contained in the folder/virtual drive. And, of course, you may mount more than one folder/virtual drive at once. In our case, since we have four CD-ROMs, we will want to mount all of them at the same time, so as not to be bothered with mounting and unmounting CD-ROMs during our game play.

Actually, this is a good practice, when you have to use applications that need one or more CD-ROMs or DVD-ROMs. Suppose you need to install and use many applications and each one of those needs from 1 to 15 CD-ROMs in order to function. What would you do? Well, I will provide a method in the appendix at the end of this blog post, but you will understand the concepts and one way of proceeding just below.

The way of proceeding I am referring to is the use of DOSBox. Well, this method is valid only if we have DOS applications, whereas the methods I will show you in the appendix cover Windows applications. Since Lands of Lore Guardians of Destiny can run in DOS, we can use the DOSBox method I will now describe. DOSBox is not only an emulator that you can use to run DOS applications, but it also provides you with the ability to create virtual drives, just as Alcohol or PowerISO do. Thus, not only will we be able to run the game in a modern version of Windows (but inside DOSBox), but DOSBox will also allow us to mount the CD-ROMs of the game. So, we have a double win.

But, as far as I know, DOSBox does not support .mdf or .mds fiels, whereas it supports mounting folders with regular files. So, before mounting the CD-ROMs, we first have to extract each CD-ROM’s content to a different folder, using Alcohol or PowerISO (or any other similar utility).

Please note that we can skip this step and use Alcohol or PowerISO to mount the virtual drives. This way, DOSBox will reference these drives and we will only use DOSBox to install and run the game. We will not use DOSBox’s ability to mount the drives, since this function will be provided by Alcohol or PowerISO. But I find that it is better to avoid having yet another utility running and serving the CD-ROM content to DOSBox, when DOSBox is perfectly capable of doing this on its own.

So, let us begin.

Install Alcohol or PowerISO and extract the contents of each CD, either by mounting it and then copying it the contents, or just by extracting the contents from the .mdf of .mds file, depending on the utility you are using. Please note the volume label, because some games may check for it to find if it is available on the virtual volume you will create. The volume labels are LOLG_CD1, LOLG_CD2, LOLG_CD3, LOLG_CD4 fro the four CD_ROMs respectively. So, let us keep use these names to create four folders in the root of drive C: (bad practice by the way, since we are “polluting” the root namespace) and let us put in each folder the contents of the respective CD-ROM.

So we now have the following four folders, containing the contents of the four CD-ROMs:

  • C:\LOLG_CD1
  • C:\LOLG_CD2
  • C:\LOLG_CD3
  • C:\LOLG_CD4

We may now download and install DOSBox. The current version as of now is 0.74.

There are three main folders pertaining to DOSBox installation. First, we have the folder DOSBox-0.74 where the program is installed in the Program Files folder. Then we have the folder C:\dosbox\ which the program creates and considers its root, file system wise. When the program (DOSBox) starts, it sets the current directory there and you cannot go higher by “CD ..”. Lastly, there is the folder DOSBox in your user profile folder and under AppData\Local\. This folder is important because inside it you will find the dosbox-0.74.conf file, which stores the settings for the DOSBox configuration. Actually, you may need to change the following settings and set them as follows, in order for the game to function properly:

output=ddraw
fullresolution=1920 X 1080
scaler=normal3x
aspect=true

Please note that the fullresolution value is provided an example (and is the resolution of the screen that I am currently using). Please substitute the value “1920 X 1080” with the resolution of your screen.

The file dosbox-0.74.conf  has a section at the end where you can put DOS and DOSBox commands and they will be executed each time DOSBox starts. We will not need to put any commands there. Whatever commands we may need, we will put them in batch files and execute them (by typing the name of each batch file) after DOSBox starts. To create  mount the necessary drives and to run the gane, we will need only one batch file.

Let us create the following batch file, named LOLG.BAT, in the C:\dosbox folder:

ECHO ON

MOUNT -U D
MOUNT -U E
MOUNT -U F
MOUNT -U G

MOUNT D C:\LOLG_CD1 -T cdrom -LABEL LOLG_CD1
MOUNT E C:\LOLG_CD2 -T cdrom -LABEL LOLG_CD2
MOUNT F C:\LOLG_CD3 -T cdrom -LABEL LOLG_CD3
MOUNT G C:\LOLG_CD4 -T cdrom -LABEL LOLG_CD4

Please note that the batch file and I assume that the drive letters from D onwards are available.

We can run this batch file by typing its name in the DOSBox console. This batch files loads all four CD-ROMs. Actually, to install the game, we only needed to mount only the first CD-ROM. We can change the current drive to D and run setup.exe from there:

D:
SETUP

SETUP will create a folder named WESTWOOD in C:\DOSBOX\ (our root) and it will then install the game there.

Let me explain the commands in LOLG.BAT.

ECHO ON is for displaying the command that is executed.

UMOUNT is for unmounting the drive letter that follows the command. When you first run the batch file, after each time DOSBox starts, there is no need to run UMOUNT, because no drive letters will be mounted, (other than C:\DOSBOX as C:). But it is a good practice to unmount any drive letters that you are planning to mount, in case you may need to run the batch file more than once in a session, especially if there has been some other drive mounting in between.

MOUNT is for mounting the drive letter that follows the command. The contents of the folder that follows are the contents of the drive. -T specifies the mode that will be emulated. -LABEL specifies the volume label that will assigned to the drive volume. Please note that although DOSBox considers the file system root to be at C:\DOSBox, the DOSBox MOUNT command sees all your PC’s file system and disks, so the C:\DOSBox root does not apply to the MOUNT command.

After installation of the game is complete, you can change the LOLG.BAT as follows, in order to run the game:

ECHO ON

MOUNT -U D
MOUNT -U E
MOUNT -U F
MOUNT -U G

MOUNT D C:\LOLG_CD1 -T cdrom -LABEL LOLG_CD1
MOUNT E C:\LOLG_CD2 -T cdrom -LABEL LOLG_CD2
MOUNT F C:\LOLG_CD3 -T cdrom -LABEL LOLG_CD3
MOUNT G C:\LOLG_CD4 -T cdrom -LABEL LOLG_CD4

C:
CD \WESTWOOD\LOLG\
LOLG.EXE

So, by typing LOLG (you can always omit the .BAT extension for batch files) in the root of the DOSBox console, the game will run, having all CD-ROMs fully loaded – no need to change CD-ROMs during game play.

Please note that you can change DOSBox and the application that it runs from full screen to a window and vice versa by simultaneously pressing ALT and ENTER (holding ALT and pressing ENTER).

Appendix

So you have seen how you can install and run a DOS application that uses one or more CD-ROMs. DOSBox is a great solution, because it is not only an emulator, but it also provides virtual drive creation and mounting capability.

So, if you have one or more DOS applications that you need to run, you can create a batch file for each of these applications. Each batch file will unmount the drive letters it needs to use for the application and then mount them using the folders that contain the contents of the respective CD-ROMs for the application.

Let us suppose that we have one DOS application that needs four drive letters, and another that needs six drive letters. To run any application, only one at a time, in any order, each batch file only needs to unmount and mount the drive letters the application needs. Say for example that we run the application that needs six drive letters. Its batch file will unmount and then mount the drive letters D, E, F, G, H, I. We exit this application and then we run the application that needs four drive letters. If its batch file unmounts all six drive letters and then mounts the four drive letters that it needs, then this is excellent. But even idf its batch file unmounts only the four drive letters that the applications needs, it is fine. The drive letters H, I will remain mounted in the other applications contents, but they will be ignored by the current application.

Actually, the perfect way to do this is to create a file with the drive letters that you want to have available for mounting and unmounting. Then each batch file will read this file and unmount each and every one of these drive letters, before mounting any drive letters that the respective application needs. This way, you can adjust the available drive letters from time to time and from PC to PC. But you do not have to go to such extremes, since I already explained that it is perfectly file for each batch file to unmount and mount only the amount of drive letters that the application needs, leaving any (higher) drive letters as they were from any previous use of other applications that needed more drive letters. Another idea. is to create a batch file that only unmounts all drive letters you may want. You may run it whenever you want and each application batch file can call it at its beginning.

What you cannot do with this method, is run both applications simultaneously. Actually, if you need to run two or more such applications simultaneously, you should create a batch files that loads all CD-ROMs for these applications. There is a limit to this practice, thought, since only 26 drive letters can exist (the English alphabet has this limit) and also, some of these drive letters are used, like C: for the actual hard disk of the PC.

DOSBox can be used for DOS applications. What can we do if we want to accomplish the same results for Windows applications? What can we do if we want to run lots of applications, one at a time (that is the restriction), when each application needs one or more CD-ROMs or DVD-ROMs to be mounted?

In this case, we will again use batch files to unmount and mount the contents of the respective CR-ROMs or DVD-ROMs, but we will not use DOSBox, since DOSBox can only run DOS applications.

One method we can use is the command line SUBST command. Just like DOSBox’s MOUNT command, SUBST mounts a drive letter with the contents of the folder you specify. And this command line command comes with the operating system – no need to install anything extra. The following batch file prepares the PC to run RIVEN, using the drive letters P through T, after I copied the contents of the five RIVEN CD-ROMs in five respective folders:

SUBST P: /D > NUL
SUBST Q: /D > NUL
SUBST R: /D > NUL
SUBST S: /D > NUL
SUBST T: /D > NUL

SUBST P: "C:\RIVEN1"
SUBST Q: "C:\RIVEN2"
SUBST R: "C:\RIVEN3"
SUBST S: "C:\RIVEN4"
SUBST T: "C:\RIVEN5"

Another method is to use Alcohol to create .mdf/.mds files from the contents of your CD-ROMs. Then specify how many virtual drives you want to have. Lastly, you can use batch files to unmount and mount these files, using Alcohol’s command line program AxCmd, that Alcohol provides exactly for this kind of automation.

The following batch file assumes that I used Alcohol 52% to specify that my PC will have (at least) 5 virtual drives. The 5 .mds files that correspond to the 5 RIVEN CD-ROMs are in the folder C:\Games\Alcohol\. The batch file will prepare the PC to run RIVEN and will load the five .mds files, each one at the next available virtual drive.

C:

CD "C:\Program Files\Alcohol Soft\Alcohol 52"

AxCmd 1: /U
AxCmd 2: /U
AxCmd 3: /U
AxCmd 4: /U
AxCmd 5: /U

AxCmd 1: /M:C:\Games\Alcohol\Riven1.mds
AxCmd 2: /M:C:\Games\Alcohol\Riven2.mds
AxCmd 3: /M:C:\Games\Alcohol\Riven3.mds
AxCmd 4: /M:C:\Games\Alcohol\Riven4.mds
AxCmd 5: /M:C:\Games\Alcohol\Riven5.mds

Thus, in this blog post you learnt what to do if you have lots of applications that each requires lots of CD-ROMs or DVD-ROMs and you want to run each application, (one application at a time), without having to physically insert and remove disks. The obvious downside is that you need an amount of disk space roughly equal to the size of the contents of all the disks of all the applications.

Posted in Administration

Learn how to count in any numbering system

In this blog post, I will teach you how to count in any numbering system. I have also created a program that counts in any numbering system and I will show you this program in the second part of this blog post.

I have  a shared folder pertaining  to this blog post that you are free to visit and download its contents. You may visit the shared folder at the following link: Count in any numbering system. In this folder, you will find:

  • An Excel spreadsheet with two tabs, that may help you in your learning.
  • A text file that contains the source code of the program (in C# with .NET framework version 2.0) that counts in any numbering system.
  • A zip file that contains the complete Visual Studio Windows Forms C# project (that also contains the source code of the program that counts in any numbering system.)
  • An executable file, which is the Windows program that counts in any numbering system. You can copy the executable file in any folder of your Windows OS and run it. It needs no installation, but you need to have the Windows .NET framework (version 2.0 at least) in order to execute the program.

OK. First things first: How to count in any numbering system.

We (humans) use the base-10 numbering system. Why? Well, all numbering systems are equivalent, but we chose the base-10 numbering system because we have ten fingers, and we find counting in tens to be more intuitive and convenient. We are used to counting in tens, so we chose a numbering system that corresponds to this counting manner.

If we were a species with three fingers (three fingers altogether, and to keep the symmetry we might have had three hands, each hand having only finger, or only one hand with three fingers, or even two hands, one with two fingers and the other hand with only one finger, but then these two hands might be in opposite directions in order to keep the symmetry of our body) we might have chosen to use the base-3 numbering system for counting, because we would want to count in threes.

The smallest base that can exist is base-2. In base-2, we have two digits: 0, 1.

In base-3, we have three digits: 0, 1, 2.

And so on.

In base-10, we have 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

In base-11, we have 11 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A. (We use letters because we run out of number symbols. Actually we may use any symbol for any number. So, if, for example, we replace 0 with &, and 1 with *, and 2 with %, etc, we will have an equivalent representation).

In base-16, we have 16 digits:  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.

And so on.

Here is how to count in any-numbering system:

Example in base-2, which means that the digits are 0, 1.

Start from 0, which is equal to infinite zeros: …000000

Increase the rightmost digit.

...000000
...000001

When the rightmost digit cannot increase any more,
set the rightmost digit to zero
and increase the second rightmost digit.

...000010

Continue to increase the rightmost digit,
keeping the other digits as they are.

...000011

When the rightmost digit cannot increase any more,
set the rightmost digit to zero
and increase the second rightmost digit.
But if the second righmost digit cannot increase anymore,
set it to zero as well
and increase the third rightmost digit.

...000100

And so on:

...000101
...000110
...000111
...001000
...001001
...001010
...001011
...001100
...001101
...001110
...001111
...010000
...010001
.........

And so on…

Example in base-3, which means that the digits are 0,1,2.

Start from 0, which is equal to infinte zeros: …000000

Increase the rightmost digit.

...000000
...000001
...000002

When the rightmost digit cannot increase any more,
set the rightmost digit to zero
and increase the second rightmost digit.

...000010

Continue to increase the rightmost digit,
keeping the other digits as they are.

...000011
...000012

When the rightmost digit cannot increase any more,
set the rightmost digit to zero
and increase the second rightmost digit.

...000020

Continue to increase the rightmost digit,
keeping the other digits as they are.

...000021
...000022

When the rightmost digit cannot increase any more,
set the rightmost digit to zero
and increase the second rightmost digit.
But if the second righmost digit cannot increase anymore,
set it to zero as well
and increase the third rightmost digit.

...000100

And so on:

...000101
...000102
...000110
...000111
...000112
...000120
...000121
...000122
...000200
...000201
...000202
...000210
...000211
...000212
...000220
...000221
...000222
...001000
...001001
...001002
...001010
...001011
...001012
...001020
...001021
...001022
...001100
...001101
...001102
...001110
...001111
...001112
...001120
...001121
...001122
...001200
...001201
...001202
...001210
...001211
...001212
...001220
...001221
...001222
...002000
...002001
...002002
...002010
...002011
...002012
...002020
...002021
...002022
...002100
...002101
...002102
...002110
...002111
...002112
...002120
...002121
...002122
...002200
...002201
...002202
...002210
...002211
...002212
...002220
...002221
...002222
...010000
...010001
.........

And so on…

Additional notes:

So now you know how to produce the numbers of any base in ascending order. There is another way to produce the numbers of any base in ascending order. This is done by writing vertically each digit column starting from the rightmost digit column. So, you create the rightmost digit column by writing each number once starting from 0 then 1 and so on. When the digits finish, you start over. So, for base 2, you write:

....0
....1
....0
....1
....0
....1
....0
....1
.....

Then you create the second rightmost column by noticing the repeating pattern of the rightmost column and matching it with one digit in the second rightmost column, starting from zero. The repeating pattern of the rightmost column is 0-1. So you create the second rightmost column as follows:

...00
...01
...10
...11
...00
...01
...10
...11
.....

As you may notice, the repeating pattern of the second rightmost column is 0-0-1-1.

So you create the third rightmost column as follows:

..000
..001
..010
..011
..100
..101
..110
..111
.....

The repeating pattern of the third rightmost column is 0-0-0-0-1-1-1-1.

And so on.

For base-3, the repeating pattern of the rightmost column would be 0-1-2. The repeating pattern of the second rightmost column would be 0-0-0-1-1-1-2-2-2. The repeating pattern of the third rightmost column would be 0-0-0-0-0-0-0-0-0-1-1-1-1-1-1-1-1-1-2-2-2-2-2-2-2-2-2. And so on.

Counting is important and base-2 and bases that are powers of 2, especially base-16, are very important when dealing with digital electronics and computers in low-level.  Let me explain why.

First of all, computers are created as large bundles of electronic switches. Switches, electronic or otherwise, have two states: off and on. So, engineers assign the number 0 to one of the states and the number 1 to the other state (in a consistent manner, of course) and can set each switch to any state or read any switch’s state. That’s how computations are made at a low-level. So, binary arithmetic is essential to enginners for the programming and operation of a computer. The state of each electronic switch is either 0 or 1, and 0 and 1 are the “binary” digits, or bits as they called in computer parlance. Just for your information, each electronic switch is made up from a few transistors, which can me made really tiny. A computer chip may contain billions of transistors.

OK, so base-2 and the corresponding arithmetic (binary arithmetic) of this numbering system is important to computers, But why is base-16 (hexadecimal arithmetic) also important? Well, the numbering systems of the powers of the same base have an important connection. I will now explain what this connection is. For example, let us take the number 2. The numbering systems that are powers of 2 are: base-2, base-4, base-8, base-16, base-32, base-64, and so on. The conversion between any of these numbering systems to another such system can be easily done.

Here is how: Let us study base-2 and base-16. suppose we have a number in base-16, for example B8. What is this number in base-2? To answer, we will represent each of the hexadecimal digits with 4 binary digits, since we need 4 binary digits to represent the highest hexadecimal digit (F in base-16 is 1111 in base-2). So, we have the number B8, and B in base-16 is 1011 in base-2, and 8 in base-16 is 1000 in base-2. The important property of numbering systems of powers of the same base allows us to find a number’s equal in another such base, as follows: We substitute each digit from the higher base to the equivalent digits of the lower base, or we group the digits of the lower base to the equibalent digits of the higher base. In the case of the base-16 number B8, it is equal to 10111000 in base-2, where the first four binary digits correspond to B and the next 4 binary digits correspond to 8.

Another example: Given the base-2 number 110100011, what is the equivalent base-16 number? Well we will group the digits by four’s, starting from the right and adding leading zeros if we need to. So our number becomes: 0001 1010 0011. Substituting each group of 4 digits with its hexadecimal equivalent gives us the base-16 number 1A3.

This property is very important to computing and one of the reasons engineers chose to represent information in bytes. Each byte is an ordered set of 8 bits. By choosing bytes to be comprised of 8 bits each, it makes their representation very easy: Each byte can be represented by two hexadecimal digits. So a byte with the following value in bits: 00100100, can be represented as 24 in hexadecimal (base-16).

I found that knowing how to count in base-2 was enough to solve any IP (Internet Protocol) subnetting problem that I ever encountered! Of course, it will be very beneficial to you if you learn how to do other operations as well (beyond counting. like addition, subtraction, multiplication, division, transformation of a number from one base to another).  And, if you will be dealing with computers, you may often encounter base-2 and base-16 number representations.

My program which counts in any numbering system

I created a program in C# that counts in any numbering system. I will present the code below and you can also download the code or even the complete Visual Studio project from the link I provide in the beginning of this blog post.

If you want to recreate the project yourself, just create a new project in Visual Studio as a Windows Forms C# application. In a form place two textboxes, a button and a DataGridView. You may also place two labels, to show what each textbox use is. And then, use my code as the form’s code.

You, may see what the form looks like below:

In the first textbox, you enter the base for which you want to count. Counting will start from 0 up to the number you want. You must specify this number in its base-10 representation in the second textbox. When you press the button, the program will create two columns in the datagridview. The first column will contain the numbers in base-10 for your reference and the second column will contain the equivalent numbers in the base you specified in the first textbox.

In the code you will see that there is a string (array of characters) called strDigitSymbols. These are the digits that the program uses to construct the numbers in the second datagridview column. So, even if the program “knows” for sure it “wants” to use a 0 or a 1 in the second gridcolumn, it will never put 0 or 1, but instead it will put  strDigitSymbols.Substring(0, 1) instead of 0 and strDigitSymbols.Substring(0, 1) instead of 1. This is because I want to let the user specify alternate symbols, should she wish to do so. Thus, whereas the “normal” strDigitSymbols would be “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ”, the user is allowed to replace it with whatever string she wishes, for example “%#*@(F4SL!)-+0=”, No, this is not swearing, it is a string with 15 characters, which means that the program can count for bases up to base-15. The string I have put in the program contains 36 characters, which means that the program, as is, can count up to base-36. You can add more digits to the string, so you can request counting in even larger bases. The program can count up to the base that has the same number as the number of digits that exist in strDigitNumbers.

As for the first datagridview column, it is in base-10 for your reference and does not look in the strDigitSymbols to get its symbols. The program uses regular good old decimal digits for the first datagridview column.

Here is the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Count
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            const string strDigitSymbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            dataGridView1.Rows.Clear();
            dataGridView1.Columns.Clear();
            dataGridView1.Refresh();

            bool isNumerical;

            int intBase = 0;

            isNumerical = false;
            isNumerical = int.TryParse(textBox1.Text, out intBase);
            if (!isNumerical)
            {
                MessageBox.Show("The base number must be an integer equal or greater than 2", "Error in the base number: Not an integer.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (intBase < 2) { MessageBox.Show("The base number cannot be less than 2.", "Error in the base number: Too small.", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (intBase > strDigitSymbols.Length)
            {
                MessageBox.Show("There are not enough digit symbols to represent the numbers for the base number you requested.", "Error in the base number: Too big.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int intMaximumCount = 0;

            isNumerical = false;
            isNumerical = int.TryParse(textBox2.Text, out intMaximumCount);
            if (!isNumerical)
            {
                MessageBox.Show("The number in base-10 to count up to must be a positive integer", "Error in the count number: Not an integer.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            dataGridView1.Columns.Add("Base 10", "Base 10");
            dataGridView1.Columns.Add("Requested Base", "Requested Base");

            dataGridView1.Columns["Base 10"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;
            dataGridView1.Columns["Requested Base"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight;

            dataGridView1.Columns["Base 10"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomRight;
            dataGridView1.Columns["Requested Base"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomRight;

            string strPreviousNumber = strDigitSymbols.Substring(0, 1);

            dataGridView1.Rows.Add(0, strPreviousNumber);

            string strNextNumber;
            string strDigit;
            string strNextDigit;
            int i;
            bool blnFinished = false;

            for (int intCount = 1; intCount <= intMaximumCount; intCount++)
            {

                // We begin each for iteration with the strPreviousNumber set at the end of the pevious for iteration.
                // The goal of each for iteration is to find the strNextNumber, which is the number that succeds the strPreviousNumber.

                strNextNumber = "";
                strDigit = "";
                strNextDigit = "";
                i = 0;
                blnFinished = false;

                // We will get each digit of the previous number starting from the right of the previous number,
                // using i as the counter to access the digits of the previous number.

                while (true)
                {
                    // Get next digit of the previous number from the left.

                    strDigit = strPreviousNumber.Substring(strPreviousNumber.Length - 1 - i, 1);

                    // For the digit obtained, find the coresponding digit that succeeds it,
                    // using j as the counter to scan strDigitSymbols.

                    for (int j = 0; j <= intBase - 1; j++)
                    {
                        if (strDigit == strDigitSymbols.Substring(j, 1))
                        {
                            // We found the digit and now we will take the corresponding digit that suceeds it and then we will break from the inner for loop.

                            if (j < intBase - 1) { // If we are here, it means that we have the "normal" case where the next digit is greater than the previous digit. // Example in Base-10: strDigit = "6", thus strNextDigit = "7". // Because this kind of incementation will happen, we will set blnFinished to true, in order to break from the while loop. strNextDigit = strDigitSymbols.Substring(j + 1, 1); if (strPreviousNumber.Length - 1 - i > 0)
                                {
                                    // If we are here, it means that there are more digits of the previous number to the left of the digit we are processing.

                                    strNextNumber = strPreviousNumber.Substring(0, strPreviousNumber.Length - 1 - i) + strNextDigit + strNextNumber;
                                }
                                else
                                {
                                    // If we are here, it means that there no are more digits of the previous number to the left of the digit we are processing.

                                    strNextNumber = strNextDigit + strNextNumber;
                                }

                                // We finished processing and we need to break from the while loop.

                                blnFinished = true;
                            }

                            if (j == intBase - 1)
                            {
                                // If we are here, it means that the next digit is the first in strDigitSymbols.
                                // Example in Base-10: strDigit = "9", thus strNextDigit = "0".\
                                // Because this kind of incementation will happen, we will not set blnFinished to true, in order to continue looping in the while loop.

                                strNextDigit = strDigitSymbols.Substring(0, 1);
                                strNextNumber = strNextDigit + strNextNumber;
                            }

                            break; // Break from the inner for loop.

                        } // End of the outer if statement.

                    } // End of the inner for loop.

                    if (blnFinished == true)
                    {
                        break; // Break from the while loop.
                    }

                    i++;

                    if (i == strPreviousNumber.Length)
                    {
                        break; // Break from the while loop because there are no more digits to process.
                    }

                } // End of the while loop.

                if (blnFinished == false)
                {
                    // If we are here, it means that all digits have been turned to zero, 
                    // so we need to add a "1" in front of all these zeros.
                    // Example in Base-10: strPreviousNumber = "9999", thus strNextNumber = "10000".

                    strNextNumber = strDigitSymbols.Substring(1, 1) + strNextNumber;
                }

                dataGridView1.Rows.Add(intCount, strNextNumber);

                // We begin each for iteration with the strPreviousNumber set at the end of the pevious for iteration.
                // The goal of each for iteration is to find the strNextNumber, which is the number that succeds the strPreviousNumber.

                strPreviousNumber = strNextNumber;

            } // End of the for loop.

        } // End of the button1_Click.

    } // End of the class.

} // End of the namespace.

The outer for loop is used to count from 0 to the decimal number in the second textbox. This represents up to how many numbers we will count. The counter for this for loop is a regular decimal numbers and is used to populate the first datagridview column for your reference. In each outer for loop iteration, the program finds the number that will go in the second datagridview column, based in the base you requested in the first textbox. How does the program find the number in the requested base? Well, the first number is 0, or, rather, the first number in strDigitSymbols. In each outer for loop iteration it uses the knowledge of  what the previous number was and it scans the previous number’s digits as well as the strDigitSymbols digits, to deduce the “current” number.

The program never break form the outer for loop. The loop continues until it reaches the number you have specified in the second textbox.

In each for loop iteration, the program uses a while loop to scan the digits of the previous  and an inner for loop to scan the strDigitSymbols. This way, the program can deduce the next number in the sequence.

The program is heavily commented, so you may understand its inner workings.

Posted in Development

Ellis Island in perpetuity

Tl;dr: When speaking about a Greek male, use his name including the final “s” in his name. When speaking to a Greek male, address him by omitting the final “s” in his name. When you ask a Greek male “What’s your name?”, expect him to include the final ”s” in his name. When you ask a Greek male “What do they call you?”, expect him to omit the final “s” in his name. All these rules follow from the Greek language grammar and are valid for both first and last names.

I think that you must be very puzzled after reading the title and the abstract (tl;dr). What does Ellis Island, perpetuity, and some obscure Greek grammar rules about name calling have to do with each other?

Well, let me explain.

When I watch American movies or American TV series, I sometimes look at the credits. And sometimes I find Greek names there. And other times I find names that might as well be Greek, but I am not sure. Obviously, Greek names are spelled according to the grammatical rules of the Greek language. If I find small discrepancies and deviations from the Greek grammar in a name, I cannot be 100% sure this is a Greek name.

But I have a theory as to why some of these names, that might be Greek, actually are.

Let me use an example. Suppose I watch a movie and in the credits I see the name “John Athanasio”. In such a case, I immediately start shouting: “Ellis Island! Ellis Island!”. Why do I do that and what do I mean?

To cut a long story short, I make the assumption that in the old days, a Greek person whose first name was “Athanasios” came to America crossing the ocean in a boat, being miserable, tired and malnourished. Before arriving at the States, he was taken to Ellis Island to be examined and to be given new identification papers.

Athanasios, unable to speak the English language, barely understood what was happening around him. At some point, the officers there wanted to provide him with identification papers, in order to release him to New York, his new home.

So, they the officers called an officer or interpreter who spoke Greek, to help them communicate with Athanasios.

Perhaps, there was no officer there who actually spoke Greek. There might have been someone there who only knew how to formulate the most basic questions in Greek.

Anyway, the translator would try to communicate with Athanasios. So, what would the translator ask Athanasios? The translator would first ask for Athanasios’ name.

Well, here we have a problem. How would the translator ask Athanasios about his name?

He could ask Athanasios in Greek: “What’s your name”. Or he could ask Athanasios in Greek: “What do they call you?”.

In English, the most common phrase to ask for the other person’s name is “What’s your name”. If Athanasios was literally asked that in Greek, he would answer “Athanasios”.

In Greek, the most common phrase to ask for the other person’s name is “What do they call you?”. If Athanasios was literally asked that in Greek, he would answer “Athanasio”. Please note the omission of the final “s”.

I assume that the translator had asked a Greek person how to say “What’s your name”. The Greek person told him to say “What do they call you?”. This answer is correct in the respect that, the most common way to say that in English is translated to the most common way to say that in Greek.

But the answer is incorrect in the respect that it is not literal.

“What is your name?” literally translated in Greek yields the response: “Athanasios”. “What do they call you?” literally translated in Greek yields the response: “Athanasio”. Again, please note the omission of the final “s”.

To yield the desired response, the translator should have been literally asking “What is your name?” in Greek, which, by the way, in Greek, is less frequent and more awkward than “What do they call you?”.

Suppose we have a Greek male whose name is “Athanasios. ”When another native Greek wants to find this male Greek’s name, they ask him: “What do they call you?”. He will answer: “Athanasio”. Then they will know that his name is ”Athanasios”.

I suppose that level of sophistication eluded the translators in Ellis Island. Perhaps they had a few “canned” questions translated in many languages. And, unfortunately, the person that translated “What’s your name?” in Greek, should have had the foresight to insist on translating not the question “What’s your name?” but the question “What do they call you?”.

This is because “What do they call you?” yields the correct name, instead of “What’s your name?”, which yields the name without the final “s”.

So, poor Athanasios, disoriented and tired, at some point in his Ellis Island stay, heard a few words in his native language: “What do they call you?”. Rejoicing, he replied: “Athanasio!”.

Scribble, scribble, scribble… Inscribed. Papers ready.

Now, you might think that my fictitious story is quite unrealistic.

First of all, you would think that the officers in Ellis Island did not only want the first name of Athanasios, but also his last name. And, of course, you would be right in your thinking. I just used only the first name as a tool to make emphasis. Writers are allowed to do that.

Ok, so more realistically: Suppose Athanasios full name is Athanasios Samaras, a common first name and last name in Greece. So, they ask Athanasios: “What do they call you?”. Rejoicing, he replied: “Athanasio Samara!”.

Scribble, scribble, scribble… Ok, you know the rest.

Please notice the absence of the final “s” from both the first and the last name of Athanasios.

By now, you might have guessed how the story ends and you might also have another objection.

Athanasios goes out into the world (of New York) and after many years of struggles, he manages to become a respected member of the community. But everywhere he went, people looked at his papers and told him not to confuse them: “Don’t confuse us! You said your name is ‘Athanasios’, but your papers write ‘Athanasio’. Be careful, or we might think you are a liar.”

So, poor Athanasios, desperately trying to fit in, would gladly accept what his papers were saying and would also gladly repeat it.

And after many years, he had children and grand children and so on, and they inherited his legacy and story and name, and yes, first name as their last name!

This might have been your objection all along: How come a first name can become a last name?

Obviously, most probably, the descendants of Athanasios would have inherited his last name: “Samaras”, or rather, “Samara”, as it was erroneously written down in Ellis Island. But there is also the chance that Athanasios was so important to his family tree and to others in the community, that knew his family tree, that his family tree started being identified by him. After all, he was the first one in America.

So, sometimes it just so happens that the family may also change its last name in order to denote the first name of the man who started the family tree in America.

Recapitulation: The correct way to write and say the name is “Athanasios Samaras”. The question: “What’s your name?” in Greek, yields the answer: “Athanasios Samaras.” The question: “What’s your name?”, yields the answer: “Athanasio Samara.” So, when a Greek hears the response “Athanasio Samara” they know that his name is “Athanasios Samaras”. The problem is that, usually, the question in English for someone’s name is “What’s your name?” and the question in Greek for someone’s name is “What do they call you?”.

I just want to add that it is nice to have foresight and empathy. It is nice to think ahead and above and beyond. If a Greek person was asked to provide canned questions to the officers at Ellis Island, this person should have had the foresight to go against the normal way to speak Greek, providing the phrase “What’s your name?” in Greek, instead of the phrase “What’s your name?” in Greek.

But people aren’t usually so perceptive or caring.

Posted in Management

Individual bit manipulation techniques in assembly

The unit of information is the bit. It takes only one binary digit, either the value 0 or the value 1. A byte is comprised of 8 bits.

People created the byte as an ordered set of 8 bits. And they used the byte as the unit of addressable information. By that, I mean that each memory address in a computer points to a byte, not a bit.

So, memory address number 0 points to the first byte in memory. Memory address number 1 points to the second byte in memory. And so on. And the same holds true for storage. In storage, whole bytes are stored and retrieved, not individual bits.

This is for efficiency. Thus, a byte is treated as the smallest bundle of information. I guess, when people first created the bundles of information that they would use, they made an ingenious decision.

The unit of information was the bit, but to use a small ordered bundle of bits to hold an encoding of a letter or number or punctuation symbol, they would need more than four bits. This is because 4 bits correspond to 2^4=16 different permutations. And the English alphabet alone is 26 letters. Add 10 for the individual digits of the numbers (0 to 9) and add more for the punctuation symbols and other control characters that they needed for the operation of the computer (line feeds, etc.), people saw that 2^7=128 permutations were needed, which correspond to 7 bits per byte, since one byte would correspond to a letter or number or punctuation symbol or control character.

Electronic components were scarce the days those decisions were made. So 7 bits per byte would be perfectly adequate. But people made the ingenious decision to use 8 bits per byte. 8 is a power of 2, so people could calculate sizes in either bits or bytes and use the same base (2). Also, a byte could represent more symbols of information (2^8=256 permutations). Another huge reason that a byte was made to comprise of 8 bits was that in this way a byte could be represented with two hexadecimal numbers. Let me give you an example. The byte 10011110 can be represented as 9E in hexadecimal notation, since 1001 in binary is 9 in hexadecimal, and 1110 in binary is E in hexadecimal.

So, people used the concept of the byte as an ordered set of 8 bits to hold the smallest amount of information that they would address or store. A byte (which is comprised of 8 bits) would represent a character or a number from 0 to 9 or a punctuation symbol or a computer control character or another graphical symbol from a small set of predefined symbols. And of course, if a single byte would be considered to contain a purely numeric value, this would be from 00000000 in binary or 0 in decimal to 11111111 in binary or 255 in decimal.

According to all the above, it will be no surprise to learn that assembly commands also operate on full bytes. So, how will you be able to manipulate a byte’s individual bits, if the need arises?

In this blog post, I will teach you exactly that. I will show you how to use assembly commands to manipulate each individual bit of a byte. All we need in order to understand the concepts, is to study the truth tables of AND, OR, and XOR.

AND

Truth table for AND
-------------------------------------
Input bit   Input bit   Resulting bit
0           0           0
0           1           0
1           0           0
1           1           1

From the above table, we can gather the following:

If you AND any bit with 0, the result is 0.

If you AND any bit with 1, the result is the bit.

Therefore, AND can be used to set any bit of a byte to 0, regardless of the bit’s previous value.

Here is how: Suppose we have a byte and we want to set one or more of its bits to 0. All we need to do is to AND the byte with a byte that has 0’s in the bit positions that we want to set to 0 and 1’s in the bit positions that we want to remain unchanged.

Example question: Given the byte 10110010, set both the second bit from the right and the fourth bit from the right to 0.

Answer:

MOV AL, 10110010b
AND AL, 11110101b

The result is in AL (and it should be equal to 10110000).

(In the two assembly commands above, please note the suffix b, which stands for “binary”, and is used to denote that the byte is given in its 8 binary bits form.)

OR

Truth table for OR
-------------------------------------
Input bit   Input bit   Resulting bit
0           0           0
0           1           1
1           0           1
1           1           1

From the above table, we can gather the following:

If you OR any bit with 0, the result is the bit.

If you OR any bit with 1, the result is 1.

Therefore, OR can be used to set any bit of a byte to 1, regardless of the bit’s previous value.

Here is how: Suppose we have a byte and we want to set one or more of its bits to 1. All we need to do is to OR the byte with a byte that has 1’s in the bit positions that we want to set to 1 and 0’s in the bit positions that we want to remain unchanged.

Example question: Given the byte 10110010, set both the second bit from the right and the fourth bit from the right to 1.

Answer:

MOV AL, 10110010b
OR AL, 00001010b

The result is in AL (and it should be equal to 10111010).

XOR

Truth table for XOR
-------------------------------------
Input bit   Input bit   Resulting bit
0           0           0
0           1           1
1           0           1
1           1           0

From the above table, we can gather the following:

If you XOR any bit with 0, the result is the bit.

If you XOR any bit with 1, the result is the bit flipped.

Therefore, XOR can be used to flip any bit of a byte.

Here is how: Suppose we have a byte and we want to flip one or more of its bits. All we need to do is to XOR the byte with a byte that has 1’s in the bit positions that we want to flip and 0’s in the bit positions that we want to remain unchanged.

Example question: Given the byte 10110010, flip both the second bit from the right and the fourth bit from the right.

Answer:

MOV AL, 10110010b
AND AL, 00001010b

The result is in AL (and it should be equal to 10111000).

Conclusion

With AND, OR, and XOR, we can manipulate individual bits, even though these commands (as all assembly commands) operate on full bytes.

All you have to remember is these six facts:

• AND a bit with 0 and the result is 0.
• OR a bit with 1 and the result is 1.
• XOR a bit with 1 and the bit is flipped.
• AND a bit with 1 and the result is the original bit.
• OR a bit with 0 and the result is the original bit.
• XOR a bit with 0 and the result is the original bit.

I cannot let you leave like this. Here is one more example for the road:

Example question: Write a program that transforms the byte stored in the AL register. The byte should be transformed as follows: Its first bit from the right must be set to 0. Its second bit from the right must be set to 1. Its third bit from the right must be flipped. That’s it. Let’s roll. And let’s be careful out there.

Answer: These transformations cannot be performed with one operation. We will need three distinct operations. Here they are:

AND AL, 11111110b
OR AL, 00000010b
XOR AL, 00000100b

And I hope that you find obvious the fact that these operations (assembly commands) can be performed in any order. After all three operations are performed, the result will be in the AL register.

Posted in Development

The importance of “A living programmable biocomputing device based on RNA”

Please visit A living programmable biocomputing device based on RNA

Quoting:

“…have developed a living programmable “ribocomputing” device…

…based on networks of precisely designed, self-assembling synthetic RNAs (ribonucleic acid).

The RNAs can sense multiple biosignals and make logical decisions to control protein production with high precision.”

This will lead to numerous highly effective drugs that will operate “within the cell” and will be able to correct the deficiencies of each individual’s DNA.

Here is how things work.

  • The human body is made up of cells.
  • Each individual cell has a nucleus.
  • Inside the nucleus exists a DNA molecule.
  • This DNA molecule is exactly the same in every nucleus, in every cell.
  • This DNA molecule contains the instructions on how the cell will produce proteins.
  • Proteins are the structural and functional ingredients of the human body.
  • The STRUCTURAL and FUNCTIONAL ingredients of the human body.
  • This means that proteins control how the body is structured and how the body functions.
  • So, proteins control everything!
  • And the “recipe” for their formation is contained in the DNA.

So, if the DNA molecule of a person has a defect, the corresponding protein that will be produced from that DNA part will be defective and the corresponding structural or functioning part of the human body will suffer.

Now, these drugs will be made such as to control the protein formation by bypassing the defective DNA part. For these specific drugs, the tell-tale sign, from which they discover the anomaly, is found in the RNA of the cell.

These researchers have made very important progress.

Posted in Science