On 22 Lip, 09:52, Timothy Pratley <timothyprat...@gmail.com> wrote: > Could you give a more detailed example to illustrate what this means? > > > (with-bitfields arr 0 {last 1, term 1, dest 22, char 8} > > [last term dest char])
Perhaps a good illustration will be what it macroexpands to: (let [last (+ (bit-and (aget arr (unchecked-add 0 0)) 1)) term (+ (bit-shift-right (bit-and (aget arr (unchecked-add 0 0)) 3) 1)) dest (+ (bit-shift-right (bit-and (aget arr (unchecked-add 0 0)) 255) 2) (bit-shift-left (bit-and (aget arr (unchecked-add 0 1)) 255) 6) (bit-shift-left (bit-and (aget arr (unchecked-add 0 2)) 255) 14)) char (+ (bit-and (aget arr (unchecked-add 0 3)) 255))] [last term dest char]) The background is that in C99, you can declare structures like: struct foo { uint32_t last:1; uint32_t term:1; uint32_t dest:22; uint32_t char:8; }; which means that each of the fields is only that many bits long (e.g. last can only hold values 0 and 1, while dest can range from 0 to 4194303). Such a structure takes up 1+1+22+8 = 32 bits = 4 bytes in memory. It can also be written to disk, and clj-bitfields gives you a way to read it back and access the individual fields. Best regards, Daniel Janus --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---