Saturday, June 3, 2017

Zooper Binary Programming - How it Works

Awhile back, as a way of testing the AZ Screen Recorder app for Android, I created a quick short video highlighting my phone's minimalist setup:



Initially, I was thinking of creating a supplemental video detailing the programming behind my "binary calendar" setup (which I may end up doing anyway), but figured I needed to go into the mathematics behind the programming to show how the binary works.

I had originally stumbled across this blog when trying to learn how to program my own binary script.  I'd figured that trying to read a binary clock would be too much of a hassle for myself.  Besides, I was more enamored by the analog clock that I'd scripted for so long, I wanted something more elegant to subtly show the date, and so the binary calendar was born.

Anyway, after reading up on that blog I found, I couldn't quite grasp the programming initially, but it provided enough insight on why the math worked.  I'd noticed the correlation between the remainder patterns of when the numbers are divided, and how each bit in the binary is called upon.

First, a quick lesson on binary...

As the name implies, there are only 2 outcomes for an active bit: on or off... in other words, 1 or 0.  Each bit represent a set value: 1, 2, 4, 8, 16, etc.  Bits are aligned where the smallest value (1) is at the very end.

From there it's basic mathematics. Here is an example of a binary table:

4 2 1
0 0 0 0
1 0 0 1
2 0 1 0
3 0 1 1
4 1 0 0
5 1 0 1
6 1 1 0
7 1 1 1

The top row represents the bit.  The first column represents the numbers.  If, for example, we wanted to represent the number 5 in binary, we need the 3rd bit (4), and 1st bit (1) active, hence the binary equivalent is 101.

So how to we translate this table into the programming?  As previously mentioned, there's a correlation in the remainder patterns when those number are divided by those same number patterns in the bits, starting from 2, as seen in the table below:

8 4 2
0 0 0 0
1 1 1 1
2 2 2 0
3 3 3 1
4 4 0 0
5 5 1 1
6 6 2 0
7 7 3 1

For example, for each number divided by 4, the remainder is either 0 or something else.  However, we need to go a step further.  Again, looking at when the numbers are divided by 4, this actually represents the 2nd bit (2), so for each remainder value greater than or equal to 2, that represents an active bit.  You'll notice the numbers in red are the ones that match up with the binary table, just to give you a better understanding of what I'm trying to explain.

At this point, it's just a matter of applying the modulus function within Zooper's Advanced Parameters to determine the remainder, and apply it to whatever preset variable (whether it's for "time", or "date", or whatever requires a numeric value) within Zooper itself.  As an example, to determine the 3rd bit of the binary function:

$(#Zooper Preset variable#%8)>=4?true statement:false statement$

If you happened to stumble upon this blog in search of programming some binary into your Zooper widget, I hope I'd explained the concept well enough.  My apologies if it all seems a bit confusing.  This is really for someone who has invested some time already into doing some programming into Zooper, and has a basic idea of how the programming works.

No comments:

Post a Comment

Kustom-izing Android

I look back and realize that I've been dedicated to the Android environment for quite awhile.  One of the things I love about Android is...