This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Byte Class Logical Operators

3 replies
Ross Rose
Joined: 2011-09-10,
User offline. Last seen 7 hours 26 min ago.

Anyone know if there is a reason the bitwise logical operators of the
Byte class return an Int when the right hand is a Byte also?

ichoran
Joined: 2009-08-14,
User offline. Last seen 2 years 3 weeks ago.
Re: Byte Class Logical Operators
That's what the JVM does (and Java).  Scala maintains the custom.  (Probably a good idea if you think about trying to write high-performance code.)

 --Rex

On Wed, Sep 28, 2011 at 12:19 AM, Billy <rossrose69 [at] gmail [dot] com> wrote:
Anyone know if there is a reason the bitwise logical operators of the
Byte class return an Int when the right hand is a Byte also?

Ross Rose
Joined: 2011-09-10,
User offline. Last seen 7 hours 26 min ago.
Re: Byte Class Logical Operators
Odd, I've never had to convert an operation between two bytes in java to a byte because the result was an int. At any rate, doing crypto natively is really difficult. I've managed to create a bloom filter in scala, but it is not worthy of using just yet. The manipulation of bytes using bitwise operations is convoluted due to the promotion to Int.

Billy
On Sep 27, 2011, at 23:39, Rex Kerr <ichoran [at] gmail [dot] com> wrote:

That's what the JVM does (and Java).  Scala maintains the custom.  (Probably a good idea if you think about trying to write high-performance code.)

 --Rex

On Wed, Sep 28, 2011 at 12:19 AM, Billy <rossrose69 [at] gmail [dot] com (rossrose69 [at] gmail [dot] com" rel="nofollow">rossrose69 [at] gmail [dot] com)> wrote:
Anyone know if there is a reason the bitwise logical operators of the
Byte class return an Int when the right hand is a Byte also?

Bakos Gábor
Joined: 2009-06-08,
User offline. Last seen 42 years 45 weeks ago.
Re: Byte Class Logical Operators

On 2011.09.28. 20:00, Ross Rose wrote:
> Odd, I've never had to convert an operation between two bytes in java to
> a byte because the result was an int.
Maybe you were using ^=, and like operators. Those are defined to cast
back (in Java, not in Scala) to the type of the variable on left. (It
might get surprising, when you would expect an error (for example the
variable is an integral type, but the right side has a floating type),
but a silent conversion happen.)

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland