RE: Unsigned integer math exists!

From: Campbell, Robert D (UK) <"Campbell,>
Date: Mon, 17 Nov 2003 17:35:15 +0000

----boundary-LibPST-iamunique-1283086177_-_-
Content-type: text/plain


> > Wojtek,
> >
> > what about this little snippet?
> >
> > VAR msb, lsb: BYTE; x: SHORTINT;
> > msb, lsb := ...;
> > x := SHORT(msb * 256 + lsb MOD 256)
> >
> > Cheers,
> > Marc
> > Oberon microsystems, Inc.

Instead of
  msb * 256 + lsb MOD 256
I've used
  ASH (msb, 8) + lsb MOD 256
(see Lib/Mod/Misc.ReadXVector) which is a step
nearer your 'c'.

However I am just starting to use the very interesting
OpenGL library (Ogl) which uses the Component Pascal
type SHORTCHAR for unsigned bytes.

This raises the possibility of

VAR msb, lsb: SHORTCHAR; x: INTEGER;
msb, lsb := ...;
x := ASH (ORD (msb), 8) + ORD (lsb).

The SHORT in Marc's code strips unwanted sign extensions
from x; it wouldn't be needed here.

I haven't tested this idea, and if this thread does have
a lesson it is that these suggestions MUST be tested.

Which of the several possiblities is preferred is a matter
of taste & background; an application note cannot decide those.

Cheers, Robert

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
--------------------------------------------

To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
   blackbox-request{([at]})nowhere.xy

To get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.

Send any problem reports or questions related to this email list to the list owner at
   owner-blackbox{([at]})nowhere.xy

Current posting policy:

a) To post you should use the same address by which you are subscribed to the mailing list. That way, the list server will recognize you as subscriber and forward your posting immediately, without creating any overhead.

b) If, for some reason, you cannot post from the address, by which you are subscribed, your message will be moderated to avoid spam. Please understand that moderation will often cause some delay, in particular over weekends or holydays.



----boundary-LibPST-iamunique-1283086177_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFu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