SPONSORS:






User Tag List

Results 1 to 7 of 7
  1. #1
    Member
    Join Date
    Sep 2002
    Location
    Foster City, CA, USA
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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. #2
    Senior Member
    Join Date
    Jul 2000
    Posts
    117
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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. #3
    Member
    Join Date
    Sep 2002
    Location
    Foster City, CA, USA
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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. #4
    Senior Member
    Join Date
    Jul 2000
    Posts
    117
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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. #5
    Senior Member
    Join Date
    Jan 2002
    Location
    Des Moines, Iowa
    Posts
    289
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Set datatype, Type cast operator

    Need the IBM yellow book to figure it out.

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

  6. #6
    Member
    Join Date
    Sep 2002
    Location
    Foster City, CA, USA
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Set datatype, Type cast operator

    blasct,
    What's the IBM yellow book?

  7. #7
    Senior Member
    Join Date
    Jan 2002
    Location
    Des Moines, Iowa
    Posts
    289
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 09:06 AM.

Copyright BetaSoft Inc.