reading in C structs

Discussion in 'Ruby' started by Joe Van Dyk, Aug 26, 2005.

  1. Joe Van Dyk

    Joe Van Dyk Guest

    I have the following C struct:

    typedef struct
    {
    short Elev; /* vertex elevation */
    u_char Zone; /* terrain fearture type */
    u_char Mono; /* monochrome brightness value */
    ulong rgb; /* rgb color components of vertex */

    } cell_type

    The rgb values are bitshifted into the rgb ulong, and then the rgb
    ulong is converted to a network long.

    Then a bunch of those structs are written into a file. =20

    What's the Ruby way of getting the RGB values out? Is the unpack
    specification "sccN"? And then I'd unpack the network long with
    "cccc"?
     
    Joe Van Dyk, Aug 26, 2005
    #1
    1. Advertisements

  2. Joe Van Dyk wrote:
    > I have the following C struct:
    >
    > typedef struct
    > {
    > short Elev; /* vertex elevation */
    > u_char Zone; /* terrain fearture type */
    > u_char Mono; /* monochrome brightness value */
    > ulong rgb; /* rgb color components of vertex */
    >
    > } cell_type
    >
    > The rgb values are bitshifted into the rgb ulong, and then the rgb
    > ulong is converted to a network long.
    >
    > Then a bunch of those structs are written into a file.
    >
    > What's the Ruby way of getting the RGB values out? Is the unpack
    > specification "sccN"? And then I'd unpack the network long with
    > "cccc"?
    >


    IIUC, just unpack "sC6", C for unsigned char.

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
     
    Joel VanderWerf, Aug 26, 2005
    #2
    1. Advertisements

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. Darrel
    Replies:
    3
    Views:
    913
    Kevin Spencer
    Nov 11, 2004
  2. Patricia  Van Hise

    structs with fields that are structs

    Patricia Van Hise, Apr 5, 2004, in forum: C Programming
    Replies:
    5
    Views:
    910
    Al Bowers
    Apr 5, 2004
  3. Chris Hauxwell

    const structs in other structs

    Chris Hauxwell, Apr 23, 2004, in forum: C Programming
    Replies:
    6
    Views:
    885
    Chris Hauxwell
    Apr 27, 2004
  4. Baillargeon, Sonny

    Reading struct with structs

    Baillargeon, Sonny, Oct 12, 2004, in forum: Python
    Replies:
    1
    Views:
    345
    Alex Martelli
    Oct 16, 2004
  5. Paminu
    Replies:
    5
    Views:
    842
    Eric Sosman
    Oct 11, 2005
  6. Daniel Rudy
    Replies:
    15
    Views:
    1,696
    Keith Thompson
    Apr 10, 2006
  7. Tuan  Bui
    Replies:
    14
    Views:
    769
    it_says_BALLS_on_your forehead
    Jul 29, 2005
  8. The Mysterious Mr. Rocco

    Reading xml data using php in an array of Javascript structs

    The Mysterious Mr. Rocco, Dec 2, 2009, in forum: Javascript
    Replies:
    1
    Views:
    172
    Matthias Reuter
    Dec 3, 2009
Loading...