Full-adders, 32-bit adders in JavaScript

Full-Adder circuit diagram
A Full-Adder, courtesy of the Wikimedia Commons

Fascinated by a lecture as part of my CS degree pursuits (there is light at the end of the tunnel!), I  decided to build some digital circuitry beginning with logic gates and ending with a full 32-bit adder. LIVE DEMO

So here’s my question: I’ve got a 32-bit adder… What now?

Beginning with basic AND, and OR functions, (&& and || operators are native to JavaScript), I built a simple XOR function — which is the first building block not built in to JavaScript:

I wanted each gate/function to work with simple Boolean values, as in JavaScript 1==True, 0==False can get a bit messy. For formatting reasons, I return each value + 0, so they results of higher order circuits are displayed numerically in   binary, rather than a series of True, False’s

After implementing, these foundational gates, I coded up a full adder:

 Within the returned object, “c” represents the carry, and “s” represents the sum. Information about how adders function can be found at this great Wikipedia article.

While there are more complex versions, a simple 4-bit adder is just 4 full-adders daisy chained together which each carry leading into the next adder. The final carry is returned from the 4-bit adder:

16, and 32 bit adders function in the same way: several smaller units daisy chained together, returning the final carry along with the sum:

The functions can be used like so:

So here’s where you come in: What do I do with a 32-bit adder, other than build a 64-bit adder?

Few ‘Computer Science’ searches in English? I guess I’ll start writing in Tagalog

Google Trends show few searches from the United States, or in English, for advanced Computer Science topics. Perhaps I should worry less about the content of my content, and more about the language its presented? With that in mind: Pagbati, Maligayang pagdating sa MikeDoesWeb!

Pagbati, Maligayang pagdating sa MikeDoesWeb!

I have observed an interesting trend on Google Trends that leads me to believe that perhaps I should be less concerned with the subject matter of my content, and perhaps more with the language I communicate it in.

There seem to be few searches coming out of the United States && || in English for advanced computer science topics. As an example: a Google Trend search for “genetic algorithm”

Interestingly, Tehran, Iran is looking for "genetic algorithms" the hardest...

 

Look for yourself: These similar searches get nearly identical results:

I performed some number crunching on the export files Google Trends provides, and gained a bit more insight:

Google provides both a integer rank for each language used (1st, 2nd place…), as well as a decimal weight for each language.  While English routinely scored at 2nd place, the weight difference between 1st and 2nd was often 2:1 .
For example: in the Google Trend search for “Data Structures,”  Tagalog takes the 1st spot, and English the 2nd. However, the weight between the two languages is 1:0.405
Here are the weighted scores and average weight from several computer science related search queries:
language Average dynamic programming Graph Theory Functional Programming Artificial Intelligence Data Structures
Tagalog 0.63 0.375 1 1 1 1
English 0.31 0.315 0.52 0.57 0.35 0.405
Korean 0.25 1 0.725
Chinese 0.13 0.27 0.275 0.23 0.13
Swedish 0.13 0.15 0.625 0.105
Indonesian 0.08 0.345 0.23
Dutch 0.08 0.08 0.09 0.265 0.12
Arabic 0.06 0.09 0.125 0.13 0.105
Russian 0.06 0.335 0.07
German 0.06 0.075 0.09 0.205 0.03
Finnish 0.05 0.345
Danish 0.05 0.335
Thai 0.04 0.15 0.095
Romainian 0.03 0.18
Turkish 0.02 0.07 0.055
Polish 0.02 0.12
French 0.01 0.07 0.015
Italian 0.01 0.07
Portuguese 0.00 0.03
Spanish 0.00 0.025
Persian 0.00

So whats the point?

As an English speaker, United States citizen, and programmer, I’m pretty inclined to believe that English is the language of programming. In fact, observing the programming world lends me to this same conclusion:

  • Every programming language I’ve used or encountered is written in English
  • Documentation is in English
  • Programming tools (compilers, IDEs, servers…) written in English

Have the creators of programming content missed the language boat on content?  I don’t believe so. While few native English speakers understand Tagalog, it seems possible that a majority of native Tagalog speakers understand English. However, this whole revelation of the language and locations of search queries makes me re-think some of the assumptions that I have make in writing technical material, such as the use of humor, assumption of similar situations, idioms, etc…

So, when you write your next blog post, be sure to say Pagbati!  to most of your visitors.