From: Arne Vajhøj on
On 27-03-2010 23:06, Mike Amling wrote:
> Mike Schilling wrote:
>> Peter Duniho wrote:
>>> You can fix the code in at least one of two ways:
>>>
>>> � cast the literal to byte, forcing the conversion: "myArray[0] =
>>> (byte)0xc9;"
>>> � specify a literal that can fit in a byte: "myArray[0] =
>>> 0xffffffc9;"
>>
>> How intuitive that an 8-bit literal doesn't fit into an 8-bit byte,
>> but a 32-bit literal does ;-)
>>
>> A bit more seriously, I presume that 99% of people would use the cast
>> rather than try to type the right number of 'f's.
>
> To avoid the counting of Fs, you can also use
>
> myByteArray[0]=0xC9-256;
>
> to assign 0x80..0xFF to a byte.

My suggestion for easiest and most readable code is to cast
all byte values from 0x00 to 0xFF.

And occasionally spend some minutes cursing whoever
decided that byte was unsigned.

Arne
From: Lew on
Peter Duniho wrote:
>> You can fix the code in at least one of two ways:
>
>>   • cast the literal to byte, forcing the conversion: "myArray[0] =
>> (byte)0xc9;"
>>   • specify a literal that can fit in a byte: "myArray[0] =
>> 0xffffffc9;"
>

Mike Schilling wrote:
> How intuitive that an 8-bit literal doesn't fit into an 8-bit byte, but a
> 32-bit literal does ;-)
>

Neither of the literals in Pete's example is an eight-bit literal.

> A bit more seriously, I presume that 99% of people would use the cast rather
> than try to type the right number of 'f's.

And the other 1% should have done so. Code isn't just about making
the computer do the right thing, it's about documenting that thing for
future maintenance programmers.

--
Lew
From: Daniel Pitts on
On 3/28/2010 5:33 AM, Arne Vajh�j wrote:
> On 27-03-2010 23:06, Mike Amling wrote:
>> Mike Schilling wrote:
>>> Peter Duniho wrote:
>>>> You can fix the code in at least one of two ways:
>>>>
>>>> � cast the literal to byte, forcing the conversion: "myArray[0] =
>>>> (byte)0xc9;"
>>>> � specify a literal that can fit in a byte: "myArray[0] =
>>>> 0xffffffc9;"
>>>
>>> How intuitive that an 8-bit literal doesn't fit into an 8-bit byte,
>>> but a 32-bit literal does ;-)
>>>
>>> A bit more seriously, I presume that 99% of people would use the cast
>>> rather than try to type the right number of 'f's.
>>
>> To avoid the counting of Fs, you can also use
>>
>> myByteArray[0]=0xC9-256;
>>
>> to assign 0x80..0xFF to a byte.
>
> My suggestion for easiest and most readable code is to cast
> all byte values from 0x00 to 0xFF.
>
> And occasionally spend some minutes cursing whoever
> decided that byte was unsigned.
you mean signed, right?
The only unsigned primitive numeric data type in Java is char.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
From: Arne Vajhøj on
On 29-03-2010 16:51, Daniel Pitts wrote:
> On 3/28/2010 5:33 AM, Arne Vajh�j wrote:
>> On 27-03-2010 23:06, Mike Amling wrote:
>>> Mike Schilling wrote:
>>>> Peter Duniho wrote:
>>>>> You can fix the code in at least one of two ways:
>>>>>
>>>>> � cast the literal to byte, forcing the conversion: "myArray[0] =
>>>>> (byte)0xc9;"
>>>>> � specify a literal that can fit in a byte: "myArray[0] =
>>>>> 0xffffffc9;"
>>>>
>>>> How intuitive that an 8-bit literal doesn't fit into an 8-bit byte,
>>>> but a 32-bit literal does ;-)
>>>>
>>>> A bit more seriously, I presume that 99% of people would use the cast
>>>> rather than try to type the right number of 'f's.
>>>
>>> To avoid the counting of Fs, you can also use
>>>
>>> myByteArray[0]=0xC9-256;
>>>
>>> to assign 0x80..0xFF to a byte.
>>
>> My suggestion for easiest and most readable code is to cast
>> all byte values from 0x00 to 0xFF.
>>
>> And occasionally spend some minutes cursing whoever
>> decided that byte was unsigned.
> you mean signed, right?

Yes.

:-(

Arne
From: Kevin McMurtrie on
In article <4bb13bdb$0$283$14726298(a)news.sunsite.dk>,
Arne Vajh�j <arne(a)vajhoej.dk> wrote:

> On 29-03-2010 16:51, Daniel Pitts wrote:
> > On 3/28/2010 5:33 AM, Arne Vajh�j wrote:
> >> On 27-03-2010 23:06, Mike Amling wrote:
> >>> Mike Schilling wrote:
> >>>> Peter Duniho wrote:
> >>>>> You can fix the code in at least one of two ways:
> >>>>>
> >>>>> � cast the literal to byte, forcing the conversion: "myArray[0] =
> >>>>> (byte)0xc9;"
> >>>>> � specify a literal that can fit in a byte: "myArray[0] =
> >>>>> 0xffffffc9;"
> >>>>
> >>>> How intuitive that an 8-bit literal doesn't fit into an 8-bit byte,
> >>>> but a 32-bit literal does ;-)
> >>>>
> >>>> A bit more seriously, I presume that 99% of people would use the cast
> >>>> rather than try to type the right number of 'f's.
> >>>
> >>> To avoid the counting of Fs, you can also use
> >>>
> >>> myByteArray[0]=0xC9-256;
> >>>
> >>> to assign 0x80..0xFF to a byte.
> >>
> >> My suggestion for easiest and most readable code is to cast
> >> all byte values from 0x00 to 0xFF.
> >>
> >> And occasionally spend some minutes cursing whoever
> >> decided that byte was unsigned.
> > you mean signed, right?
>
> Yes.
>
> :-(
>
> Arne

As somebody who occasionally writes data processing code, I'll join you
in some cursing.

I also curse not being able to allocate arrays of object instances.
Sun's GC algorithms barely keep pace with high-end use. You'd think
this would be a priority feature to help application servers and number
crunchers.
--
I won't see Google Groups replies because I must filter them as spam