Sg2.9
Representing Binary
Recent RSS
Representing Binary
From:  Richard
Date:  29. February 2012, 18:23

Hi everyone,

I'm a student studying Architecture and looking at making an information repository. My idea is to etch binary information into block of steel. I've been achieving this currently by looking at "01110100 01101000 01101111 01110101 00100000 01010010 01101111 01101101 01100101 01101111 00111111 00100000 01000100 01100101 01101110 01111001 00100000 01110100 01101000 01111001" then drawing my hand boxes in illustrator then using a laser cutter to cut it out of plywood. Now I have stumbled across scriptographer and was hoping there would be a way to dump binary information in and get it to draw me boxes depicting the binary.

It would be great if someone could give me some pointers! Thanks for all my help,

Rich

Re: Representing Binary
From:  Eero
Date:  2. March 2012, 17:11

Hi!

I was doing something similar earlier,
here's a script that parses a string of 1's and 0's,
and colors selected objects with black/white according to the bits

With parseInt there's max limit of 32 bits ...
so you might have to make a helper function to split
your data in chunks

But i'm no "coder" :) so maybe somebody could
have a better method for this

the bit_test method is there, so you could use
decimal number as the source data/variable as well

////////////////////////

var sel = document.selectedItems;
var bin = parseInt('01110100011010000110111101110101', 2);

//bit test helper function

function bit_test(num,bit){
return ((num>>bit) % 2 != 0)
}

//go through selected items, set fillcolor according to bit state

for(i=0;i<sel.length;i++)
{

if(bit_test(bin,i)==true)
{
sel[i].fillColor = '#FFFFFF';
}

if(bit_test(bin,i)==false)
{
sel[i].fillColor = '#000000';
}

}

Re: Representing Binary
From:  adam
Date:  24. January 2014, 17:50

Ancient topic, but in case someone searches the forum of a dying piece of software for this same question, here's an easy pseudocode:
* Save the starting data as a string, not a number.
* Then, in a for loop, pull off a character at a time with charAt().
* After that, and still within the for loop, run either the '0' logic or the '1' logic.

Be careful that you watch your variable types, however. A '1' character from a string is not exactly a boolean true nor an integer 1, but it might act like it.

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Cross Hatch Raster 15.03.12