Bug 1376 : bitwise & operator 'cannot convert from int to byte'
Last modified: 2009-11-26 06:09




Status:
RESOLVED
Resolution:
WONTFIX -
Priority:
P2
Severity:
normal

 

Reporter:
Codegnome
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2009-11-26 06:03
Was trying to use '&' between two byte variables, and kept getting the
error 'cannot convert from int to byte'. Turns out the & operator only
returns an int, regardless of data type being put into it.

Reference to intended behavior:
http://processing.org/reference/bitwiseAND.html

Sample Code of bug and a (crap) workaround

// Example 1: Using & between bytes should work (by returning a byte). It
does not.
// THIS DEMONSTRATES THE BUG
byte a;
byte b;
byte c;

a = 1;
b = 15;
c = a&b;


// Example 2: The clunky workaround
byte a;
byte b;
int c;
byte d;

a = 1;
b = 15;
c = a&b; // this operation seems to return an int no matter the types used
as input
d = byte(c);


Environment:
Processing 1.0.9
OS X 10.5.8
MacBook Pro 2.33 Intel Core 2 Duo, 2 GB RAM

PS: Haven't had time to see if this 'automatic casting from byte to int' is
even working correctly; I'm guessing any issues with that could easily be
another bug in my 'workaround'.

Cheers!
Additional Comment #1 From fry 2009-11-26 06:09
Those are language semantics that we inherit from Java, not a bug.