The less-familiar parts of Lisp for beginners — deposit-field

Now we move on to deposit-field.  A cursory introduction to Lisp is unlikely to have discussed this function.  To begin, I’d suggest that you review the earlier article on byte.  The deposit-field function is used to remove a bitfield from one integer, SRC, and insert it into another integer, DST, returning the result.  How is this different from dpb, whose effects were shown in that article on byte?  In dpb, the byte specifier acts only to window DST.  That is, if the byte specifier is 5 bits wide, then the lowest 5 bits of SRC are used, regardless of the position of the byte specifier.  In deposit-field, SRC and DST are both windowed by the byte specifier, so it is possible to insert bits other than the least-significant bits of SRC.

This sort of bitfield manipulation is not used very frequently.  It’s essential when writing code to certain binary protocols, very useful for device drivers, network stacks, and things like that, but less commonly used in other applications.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


反垃圾邮件 / Anti-spam question * Time limit is exhausted. Please reload CAPTCHA.