BYTE

Post Reply
User avatar
DGDanforth
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA
Contact:

BYTE

Post 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
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: BYTE

Post by Robert »

Arghhhhh NO.

Please propose adding new numeric types (I can think of lots), but don't remove the few we have.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: BYTE

Post 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.
cfbsoftware
Posts: 204
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Re: BYTE

Post 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.
User avatar
DGDanforth
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA
Contact:

Re: BYTE

Post 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.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: BYTE

Post 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
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: BYTE

Post 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.
cfbsoftware
Posts: 204
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Re: BYTE

Post by cfbsoftware »

DGDanforth wrote:UBYTE implies that BYTE is signed. Not good.
BYTE is signed in BlackBox and GPCP.
User avatar
DGDanforth
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA
Contact:

Re: BYTE

Post 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.
Post Reply