Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30152
| From | ĵess stone <j3ss.st0n3@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Bytes [Was: Re: Driving 7-Segment LEDs on Raspberry Pi] |
| Date | 2014-10-22 06:42 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <m27jk3$shk$1@speranza.aioe.org> (permalink) |
| References | <6c324a98-b16e-4904-b014-c53fd799cb1b@googlegroups.com> <m23g28$85a$1@speranza.aioe.org> <ccc4a51a-31ee-4099-9c63-0cc2a76c6dbc@googlegroups.com> <m258kt$7t0$1@speranza.aioe.org> <m25kdv$tou$1@dont-email.me> |
In article m25kdv$tou$1@dont-email.me, Eric Sosman said... > On 10/21/2014 5:22 AM, ĵess stone wrote: >> >> Well, this *is* the language whose designers had the absolutely >> *brilliant* idea of making the only byte-sized data type signed. And >> prone to being auto-promoted to int. > > I'll agree that making `byte' signed was a regrettable choice, > but what do you find repugnant about promoting it to `int'? (And do you > have a similar objection to promoting `short'?) The problem is mainly the interaction with that and the signedness of bytes. So you end up with binary 11001001 turning into 10000000000000000000000001001001 and when you later truncate or mask off the high bytes you wind up with 01001001, which is wrong. So you have to watch that you don't lose the high bit when something causes auto- promotion. And it's tricky, because it can happen even if you have a computation "entirely in bytes", i.e. nothing but bytes in and assignment to a parameter or local of byte size. Java may still turn some of the intermediate calculations silently into ints, when it seems that work with bytes into bytes ought to not do that. Ultimately, this stems from treating bytes mainly as really small integers, assuming you'll mainly use them to do arithmetic with wider types and will want wide output, when in reality bytes are mainly used for fiddling with binary data at a low level. Preferable would have been a byte type that required explicit casts to widen, and which of course was unsigned. In theory it could still be added, by adding a "ubyte" type or similar (breaking source compatibility with older Javas by adding a new reserved word, though) with unsigned semantics and no auto-promotion to wider types -- only explicit casts or direct assignment to a wider type would widen it. For easy interoperation with legacy code it should be assignable to the existing byte type without the binary being changed (meaning that, numerically, 255 would turn into -1 when such an assignment was performed).
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Driving 7-Segment LEDs on Raspberry Pi javalaurence@gmail.com - 2014-10-20 01:28 -0700
Re: Driving 7-Segment LEDs on Raspberry Pi Gordon Levi <gordon@address.invalid> - 2014-10-21 01:42 +1100
Re: Driving 7-Segment LEDs on Raspberry Pi javalaurence@gmail.com - 2014-10-24 05:20 -0700
Re: Driving 7-Segment LEDs on Raspberry Pi Arne Vajhøj <arne@vajhoej.dk> - 2014-10-24 21:37 -0400
Re: Driving 7-Segment LEDs on Raspberry Pi ĵess stone <j3ss.st0n3@gmail.com> - 2014-10-20 17:16 +0000
Re: Driving 7-Segment LEDs on Raspberry Pi javalaurence@gmail.com - 2014-10-21 00:09 -0700
Re: Driving 7-Segment LEDs on Raspberry Pi ĵess stone <j3ss.st0n3@gmail.com> - 2014-10-21 09:22 +0000
Bytes [Was: Re: Driving 7-Segment LEDs on Raspberry Pi] Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-10-21 08:43 -0400
Re: Bytes [Was: Re: Driving 7-Segment LEDs on Raspberry Pi] ĵess stone <j3ss.st0n3@gmail.com> - 2014-10-22 06:42 +0000
Re: Bytes [Was: Re: Driving 7-Segment LEDs on Raspberry Pi] Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-10-22 08:02 +0000
Re: Bytes [Was: Re: Driving 7-Segment LEDs on Raspberry Pi] ĵess stone <j3ss.st0n3@gmail.com> - 2014-10-22 10:49 +0000
Re: Bytes [Was: Re: Driving 7-Segment LEDs on Raspberry Pi] Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-10-22 08:52 -0400
Re: Bytes [Was: Re: Driving 7-Segment LEDs on Raspberry Pi] ĵess stone <j3ss.st0n3@gmail.com> - 2014-10-22 14:00 +0000
Re: Bytes [Was: Re: Driving 7-Segment LEDs on Raspberry Pi] Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-10-22 10:43 -0400
Re: Bytes [Was: Re: Driving 7-Segment LEDs on Raspberry Pi] thinbluernime <thinbluernime3@gmail.com> - 2014-10-22 16:34 +0000
csiph-web