We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › binary vs unbinary
Page Index Toggle Pages: 1
binary vs unbinary (Read 242 times)
binary vs unbinary
Mar 16th, 2009, 12:01pm
 
Hi,

Im trying to get binary form of color, and then go back from this form, but i'm getting some error

This is the code:

color c = color(0,0,0,255);
String sss = binary(c,32);
println(sss);
println(unbinary(sss));

What i'm doing wrong?

thanks
Re: binary vs unbinary
Reply #1 - Mar 16th, 2009, 1:33pm
 
It is probably a bug.
Your code works fine with color(0,0,0,0x7F); ie. high bit at 0. It has probably a relation with the fact that ints in Java are signed.

Code:
color c = color(0,0,0,0xFF);
println(c);
String sss = binary(c, 32);
println(sss);
String hb = sss.substring(0, 1);
int val = unbinary(sss.substring(1));
if (hb.equals("1")) val -= MAX_INT + 1;
println(val);


A related thread: Re: Eclipse, Color, and Hex Codes.
Page Index Toggle Pages: 1