You are here:

# Visual Basic/VB

Question
I learned a little VB back in the day, but mostly I'm only able to program what amounts to calculators. lol. I was wondering how computers understand numbers? I mean they run on 1s and 0s, but where does it get its understanding of what "4" is worth, and that it is greater than "3"? When using simple VB formulas it seems like I'm cheating somehow. lol.

Hi James,
Computers use what is called binary, it is a base 2 system.  Usually we use a base 10 system.

A base two system works in the following way:

Where the base 10 system has place holders in the following manner
1s
10s
100s

etc

Binary place olders are as follows,
128s  64s  32s  16s  8s  4s  2s  1s

The following procedure is how to convert decimal to binary
1.  start from the location that equals the highest location that is either equal to or less then the number you are converting from decimal to binary and place a 1 in that location

2.  move to the next location to the right.  If that place holder added the previous locations with a 1 is more than the number you are looking for place 0 in that location if it is equal to or less than the number in question than place a 1 and move to the next location to the right

128s  64s  32s  16s  8s  4s  2s  1s
0          8 is greater than 4 so we place a 0
0   1          4 is equal to 4 so we place a 1
0   1   0   0    Because we got a our target number above we put 0s in every remaining place holder

So the number 4 in decimal is 100 in binary

The number 10 would look like this:
128s  64s  32s  16s  8s  4s  2s  1s
0          16 is greater than 10 so we place a 0
0    1          8 eight is less than 10 so we place a 1
0    1   0          Because 8 + 4 is greather than 10 we place a 0
0    1   0   1   0    Because 8 + 2 is 10 we place a 1 in the 2s and zeros to every other postion to the right

So the number 10 in decimal is 1010 in binary

One last one that is a little more difficult.  Today (4/8/2013) is the 98th day of the year so lets see what 98 would look like in binary
128s  64s  32s  16s  8s  4s  2s  1s
0          128 is greater than 98 so we place a 0
0     1          64 is less than 98 so we place a 1
0     1    1          64 + 32 is less than 98 so we place a 1
0     1    1    0          64 + 32 + 16 is greater than 98 so we place a 0
0     1    1    0    0          64 + 32 + 8 is greater than 98 so we place a 0
0     1    1    0    0   0          64 + 32 + 4 is greater than 98 so we place a 0
0     1    1    0    0   0    1       64 + 32 + 2 equals 98 so we place a 1
0     1    1    0    0   0    1   0   Because we reached our target number of 98 we place a 0 in every place holder that remains

So the number 98 in decimal is 110001 in binary

As far as how a computer knows one number is greater than, less than or equal to another, I am not sure.

I apologize for the formatting, it looks ok when I typed the message, however when I previewed it was all screwed up.

Kevin
Questioner's Rating
 Rating(1-10) Knowledgeability = 10 Clarity of Response = 10 Politeness = 10 Comment Yeah, I guess that will work well enough, although I already knew how to convert to binary.

Visual Basic

Volunteer

#### Kevin Watkins

##### Expertise

I have written several programs integrating with MS Office including Access, Excel, and Word. I have used control arrays as well as data arrays, text files. I have an associates degree in programming. Please do not ask questions about VBA or dot net. I can only answer questions about Visual Basic 6.

##### Experience

I have written several programs integrating with MS Office including Access, Excel, and Word. I have used control arrays as well as data arrays, text files. I have an associates degree in programming.

Education/Credentials
I have an associates degree in computer programming.