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 › convert bytes from 0 to 255
Page Index Toggle Pages: 1
convert bytes from 0 to 255 (Read 700 times)
convert bytes from 0 to 255
Oct 15th, 2009, 3:00pm
 
Code:
 	

// open a file and read its binary data
byte b[] = loadBytes("something.dat");

// print each value, from 0 to 255
for (int i = 0; i < b.length; i++) {
// every tenth number, start a new line
if ((i % 10) == 0) {
println();
}

// bytes are from -128 to 127, this converts to 0 to 255
int a = b[i] & 0xff;
print(a + " ");
}
// print a blank line at the end
println();


Just for the purpose of learning, why would someone convert a byte to another range?
Re: convert bytes from 0 to 255
Reply #1 - Oct 15th, 2009, 3:28pm
 
hmm because he uses the data he gets to color something in different gray/color/alpha values?
Re: convert bytes from 0 to 255
Reply #2 - Oct 16th, 2009, 6:16am
 
Perhaps because he finds unsigned bytes more readable than signed ones? (the minus can be easy to miss)
Page Index Toggle Pages: 1