jeffg Posted March 18, 2008 Share Posted March 18, 2008 I have this code, with an echo test statement: $jar_mask = $from_ar[5] | $to_ar[5]; echo "jar_mask: $jar_mask; from_ar[5]: {$from_ar[5]}; to_ar[5]: {$to_ar[5]}<br>"; And this is what I get in the output: jar_mask: 72; from_ar[5]: 32; to_ar[5]: 4 When I last looked, bit5 (32) or'd with bit2 (4) gave bit5|bit2, not bit7|bit3. The result should be 36, not 72.Please tell me I am not going crazy, and I am doing something wrong?Uh-oh: if I change that to $jar_mask = intval($from_ar[5]) | intval($to_ar[5]); then it works. But please could you explain why the first one doesn't. Is it doing some weird string thing? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 18, 2008 Share Posted March 18, 2008 Yeah, it's probably doing a string conversion. 72 in binary is 1001000, so it's masking the 8 and 64 bits. I'm not sure why those are both double (left-shifted 1 place) what they should be, but I would assume it's a conversion. But, when you're working with bits, it's always best to explicitly cast all of your variables so that you know what the data types are. Link to comment Share on other sites More sharing options...
jeffman Posted March 18, 2008 Share Posted March 18, 2008 Type conversion in javascript stinks. So many workarounds. Everything seems like a kludge. Wouldn't you love an "as" operator or a simple equivalent? Link to comment Share on other sites More sharing options...
jeffg Posted March 19, 2008 Author Share Posted March 19, 2008 Type conversion in javascript stinks.Umm. I assume that was a slip and you meant PHP? Thanks for the comments. It had me scratching my head till I guessed what was happening. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.