Convert INTEGER to SET

Topics related to the use of Oberon language features
Locked
Dimon
Posts: 9
Joined: Tue Jan 11, 2011 5:15 am

Convert INTEGER to SET

Post by Dimon » Mon Mar 21, 2011 1:34 pm

How do I convert a INTEGER to a SET?

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Convert INTEGER to SET

Post by cfbsoftware » Mon Mar 21, 2011 9:35 pm

If you want to typecast an INTEGER variable to a SET variable use the general typecasting function SYSTEM.VAL. e.g.

Code: Select all

VAR
  s: SET;
  i: INTEGER;

s := SYSTEM.VAL(SET, i);
Examples:

i = 0, s = {}
i = 8, s = {3}
i = 0FH, s = {0..3}
i = 0AAH, s = {1, 3, 5, 7}
i = 055H, s = {0, 2, 4, 6}

Note that this doesn't do any conversion of that sort that a function like Convert.IntToStr does, it just allows you to use SET operations on an INTEGER value as if it were a SET value. The bits in the word are not changed.

Eugene Temirgaleev
Posts: 3
Joined: Wed Sep 14, 2011 11:19 am
Location: Russia, Orel
Contact:

Re: Convert INTEGER to SET

Post by Eugene Temirgaleev » Wed Sep 14, 2011 12:03 pm

The note SET: A neglected data type, and its compilation for the ARM by Prof Wirth may be helpful for the understanding of type SET.

Dimon
Posts: 9
Joined: Tue Jan 11, 2011 5:15 am

Re: Convert INTEGER to SET

Post by Dimon » Thu Sep 15, 2011 8:13 am

Eugene, I understand differense between numbers and bits.
My quest is technical and not theoretical. Context of this
quest is in constuction or definition of some NXP LPC
controllers control registers. Control register is presents
by a 32 bits processor word but structurally it is a packed
record with logic (BOOLEAN bit) and numeric (CARDINAL 2,
4 or generally N bit width) fields.
For example:

bit 0: boolean flag
bit 1: boolean flag

...
...
...

bit 11: boolean flag
bits from 12 to 15: The number of bytes, buffers or something else
bit 16: boolean flag

...

end of example.

I was need method to produce data of this kind.

I am sorry for my English. (On OberonCore I am Dmitry Maslov).

Eugene Temirgaleev
Posts: 3
Joined: Wed Sep 14, 2011 11:19 am
Location: Russia, Orel
Contact:

Re: Convert INTEGER to SET

Post by Eugene Temirgaleev » Fri Sep 16, 2011 5:29 am

Dimon wrote:Control register is presents
by a 32 bits processor word but structurally it is a packed
record with logic (BOOLEAN bit) and numeric (CARDINAL 2,
4 or generally N bit width) fields.
...
I was need method to produce data of this kind.

Code: Select all

word := ORD(setOfBooleanFlags) + LSL(cardinalField1, field1Pos) + ... + LSL(cardinalFieldN, fieldNPos)
word := ORD({1, 11, 16}) + LSL(15, 12)

Locked