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. Advertising

  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. 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. Patricia  Van Hise

    structs with fields that are structs

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

    const structs in other structs

    Chris Hauxwell, Apr 23, 2004, in forum: C Programming
    Replies:
    6
    Views:
    587
    Chris Hauxwell
    Apr 27, 2004
  3. Paminu
    Replies:
    5
    Views:
    660
    Eric Sosman
    Oct 11, 2005
  4. Daniel Rudy
    Replies:
    15
    Views:
    1,448
    Keith Thompson
    Apr 10, 2006
  5. Tuan  Bui
    Replies:
    14
    Views:
    526
    it_says_BALLS_on_your forehead
    Jul 29, 2005
Loading...

Share This Page