Page 1 of 1

BYTE

Posted: Wed Oct 12, 2016 7:48 pm
by DGDanforth
Component Pascal Language Report
Copyright © 1994-2013 by Oberon microsystems, Inc., Switzerland.

Appendix C: Domains of Basic Types
BYTE -128 .. 127

======================================
The Programming Language Oberon
Revision 1.10.2013 / 3.5.2016
Niklaus Wirth

BYTE the integers between 0 and 255
I very much prefer the definition used by Wirth. It removes the need to use SHORTCHAR for unsigned bytes.
Comments?
-Doug

Re: BYTE

Posted: Thu Oct 13, 2016 7:27 am
by Robert
Arghhhhh NO.

Please propose adding new numeric types (I can think of lots), but don't remove the few we have.

Re: BYTE

Posted: Thu Oct 13, 2016 10:42 am
by Josef Templ
There are pros and cons on both sides, I guess.
Since BYTE is used in a lot of existing code, it cannot be changed anyway.

Re: BYTE

Posted: Thu Oct 13, 2016 11:26 am
by cfbsoftware
This issue has been already tackled elsewhere. GPCP introduces an additional type for unsigned bytes called UBYTE. It is needed there so that Component Pascal can be a full consumer of the .NET Common Language Specification (CLS) libraries. It is a numeric type, unlike SHORTCHAR.

Re: BYTE

Posted: Thu Oct 13, 2016 11:32 pm
by DGDanforth
The usual usage of byte is simply a sequence of 8 bits without interpretation of the meaning of the bit pattern.
A file of bytes can be copied without any interpretation.
Can one copy a file using (CP) BYTE? I suppose that would work but the signed aspect of BYTE makes me wonder.
UBYTE implies that BYTE is signed. Not good.

Re: BYTE

Posted: Fri Oct 14, 2016 5:49 am
by Josef Templ
In many situations there is no difference between a BYTE b being signed or unsigned.
File copy is one example. If you do a comparison, e.g. b > 0 it would make a difference.
Integer addition would not make a difference if you truncate the result to a BYTE again.

The main difference is the sign extension when converting signed BYTE to INTEGER.
The bit pattern of the BYTE itself remains unchanged in such a conversion, only the
leading bits are different from an unsigned BYTE converted to an INTEGER.

In order to get an unsigned conversion you have to add (b MOD 256).

- Josef

Re: BYTE

Posted: Fri Oct 14, 2016 8:18 am
by Robert
Josef Templ wrote:In order to get an unsigned conversion you have to add (b MOD 256).
I might use

Code: Select all

k := ORD (BITS (b) * {0 .. 7})
This converts the BYTE -11 to the INTEGER 245.
The MOD recipe converts -11 to 234.


Arrgh - Now I see it! You mean "add the code", not "add the value"!


This actually illustrates an advantaged of the CP definition. Converting from signed to unsigned is easy, going the other way, less so.

Re: BYTE

Posted: Fri Oct 14, 2016 12:58 pm
by cfbsoftware
DGDanforth wrote:UBYTE implies that BYTE is signed. Not good.
BYTE is signed in BlackBox and GPCP.

Re: BYTE

Posted: Fri Oct 14, 2016 10:00 pm
by DGDanforth
cfbsoftware wrote:
DGDanforth wrote:UBYTE implies that BYTE is signed. Not good.
BYTE is signed in BlackBox and GPCP.
Yes, but that was my point.