Tool "Binhex"
Binhex
A nice and easy tool to edit binary numbers and see them in hexadecimal and decimal. I have written it for harcoding commands for I2C sensors.
Sourcecode
This is the sourcecode written for processing, see http://processing.org/
PFont Font;
int[] Bits= {
0, 0, 0, 0, 0, 0, 0, 0
};
String[] Adr= {
"7", "6", "5", "4", "3", "2", "1", "0"
};
void setup()
{
size(320, 160);
Font= createFont("Aharoni-Bold", 15);
textFont(Font);
}
void draw()
{
background(200);
fill(255);
text("Binary", 20, 35);
noFill();
stroke(100);
rect(20, 40, 220, 60);
for (int i= 0; i < 8; i++)
{
fill(255);
text(Adr[i], 35 + 25 * i, 60);
fill(Bits[i] == 0 ? 0 : 255);
rect(30 + 25 * i, 65, 20, 20);
fill(Bits[i] == 0 ? 255 : 0);
text(Bits[i] == 0 ? "0" : "1", 35 + 25 * i, 80);
}
int num= 0;
for (int i= 0; i < 8; i++)
num|= Bits[i] * 1<<(7-i);
fill(255);
text("Hex", 260, 35);
fill(0);
text(hex(num, 2), 275, 55);
fill(255);
text("Dec", 260, 80);
fill(0);
text(num, 275, 100);
fill(230);
stroke(100);
rect( 20, 120, 80, 20);
rect(120, 120, 80, 20);
rect(220, 120, 80, 20);
fill(0);
text("Set all 0", 35, 135);
text("Set all 1", 135, 135);
text("Invert all", 235, 135);
}
void mouseReleased()
{
for (int i= 0; i < 8; i++)
{
int xmin= 30 + 25 * i;
int xmax= 30 + 25 * i + 20;
int ymin= 65;
int ymax= 65 + 20;
if (mouseX >= xmin && mouseX <= xmax
&& mouseY >= ymin && mouseY <= ymax)
{
Bits[i]= Bits[i] == 0 ? 1 : 0;
}
}
if (mouseX >= 20 && mouseX <= 100
&& mouseY >= 120 && mouseY <= 140)
{
//Set all 0
for (int i= 0; i < 8; i++)
Bits[i]= 0;
}
if (mouseX >= 120 && mouseX <= 200
&& mouseY >= 120 && mouseY <= 140)
{
//Set all 1
for (int i= 0; i < 8; i++)
Bits[i]= 1;
}
if (mouseX >= 220 && mouseX <= 300
&& mouseY >= 120 && mouseY <= 140)
{
//Invert all
for (int i= 0; i < 8; i++)
Bits[i]= Bits[i] == 0 ? 1 : 0;
}
}
Please log in to post comments.
