Thanks:  0
Likes:  0
Dislikes:  0

# Thread: Set datatype, Type cast operator

1. ## Set datatype, Type cast operator

I pulled this from the Help, but don't really understand why the result is 26 with the explanation it provided.

-----------------------------------------
The first 32 members of a SET variable can be implicitly cast as an INTEGER variable. The result is a bit mask with each set bit corresponding to a value in that SET data type that is contained in this SET variable. For example:

// Establish a COLORS data type with 6 possible colors
type COLORS is set
Red
Blue
Yellow
Green
Purple
Orange

// Create a COLORS object
COLORS CoolColors = {Blue, Green, Purple}
Print ([INTEGER] CoolColors) // prints: 26 (explicit cast)
Print (CoolColors == 26) // prints: TRUE (implicit cast)

The bit mask representing CoolColors is 0000 0000 0001 1010, which is the hexadecimal value 0x001A, or the decimal value 26.

2. ## Re: Set datatype, Type cast operator

Recall that bits are represented "backwards" ...

Thus in the example:

// Establish a COLORS data type with 6 possible colors
type COLORS is set
Red -- bit 0
Blue -- bit 1
Yellow -- bit 2
Green -- bit 3
Purple -- bit 4
Orange -- bit 5

// Create a COLORS object
COLORS CoolColors = {Blue, Green, Purple} -- bit 1, 3, and 4 would be set to "1"

Print ([INTEGER] CoolColors) // prints: 26 (explicit cast)
Print (CoolColors == 26) // prints: TRUE (implicit cast)

The bit mask representing CoolColors is 0000 0000 0001 1010, which is the hexadecimal value 0x001A, or the decimal value 26.

-- in the above string, bit 1, 3, and 4 are set to 1. Again, bits are counted from the right to the left beginning with 0.

Thus you have (2^1)+(2^3)+(2^4) which is 2+8+16 or 26.

Does that help?

------------------

3. ## Re: Set datatype, Type cast operator

Oh I see, thanks. It still took me some time reading your note and finally got it. So each member of a set is represented by a position of in a binary number. The Help could have made it a little clearer.

4. ## Re: Set datatype, Type cast operator

Ya' got it!

Yeah, you're right. It would actually be even easier if they drew a picture!

------------------

5. ## Re: Set datatype, Type cast operator

Need the IBM yellow book to figure it out.

------------------

6. ## Re: Set datatype, Type cast operator

blasct,
What's the IBM yellow book?

7. ## Re: Set datatype, Type cast operator

At one point in my life I was a Mainframe COBOL and Assembler programmer. The IBM Yellow book was a small reference book that did Hexidecimal Binary and Ascii character conversions. It also has an Assembler code references in it.

Now days we have the scientific calculator as an accessory on our computer and web sites with all the info just a click away.....

*****But for the good ol' days*******

------------------

[This message has been edited by blacst (edited 11-07-2002).]

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.40 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.