packing booleans

Discussion in 'Ruby' started by Joel VanderWerf, Jan 28, 2004.

  1. Does anyone else think it would be nice to be able to pack/unpack
    booleans? Maybe like this...

    [[true, false, true]].pack("y3") # ==> "\005"

    I just chose 'y' because it's not used (as are [jokrt]), and it suggests
    "yes", a boolean answer.
    Joel VanderWerf, Jan 28, 2004
    #1
    1. Advertising

  2. "Joel VanderWerf" <> schrieb im Newsbeitrag
    news:...
    >
    > Does anyone else think it would be nice to be able to pack/unpack
    > booleans? Maybe like this...
    >
    > [[true, false, true]].pack("y3") # ==> "\005"
    >
    > I just chose 'y' because it's not used (as are [jokrt]), and it suggests
    > "yes", a boolean answer.


    irb(main):015:0> a=[true, false,true]
    => [true, false, true]
    irb(main):016:0> [a.inject(0){|acc,x| acc<<=1; acc|(x ?1:0)}].pack "I"
    => "\005\000\000\000"

    Not exactly what you were asking for though - and it doesn't work with
    Bignums...

    robert
    Robert Klemme, Jan 28, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. array of booleans

    , Oct 1, 2005, in forum: Java
    Replies:
    4
    Views:
    541
  2. Martin Herbert Dietze

    g++: integers as booleans, no warning?

    Martin Herbert Dietze, Feb 17, 2005, in forum: C++
    Replies:
    9
    Views:
    465
    Karl Heinz Buchegger
    Feb 18, 2005
  3. Roman Suzi

    Booleans and comparison results

    Roman Suzi, Jun 24, 2003, in forum: Python
    Replies:
    0
    Views:
    699
    Roman Suzi
    Jun 24, 2003
  4. =?ISO-8859-1?Q?Gerhard_H=E4ring?=

    Re: Booleans and comparison results

    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Jun 24, 2003, in forum: Python
    Replies:
    0
    Views:
    686
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Jun 24, 2003
  5. Gerrit Holl

    Re: Booleans and comparison results

    Gerrit Holl, Jun 24, 2003, in forum: Python
    Replies:
    1
    Views:
    654
    Greg Ewing (using news.cis.dfn.de)
    Jun 25, 2003
Loading...

Share This Page