Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:software:homelab:library:bit [2010/03/08 10:39] mikk.leinien:software:homelab:library:bit [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Bitwise operations ======+====== Bitwise Operations ======
  
-Bitwise operations library contains a set of macro functions to do common bit manipulation operations. They are used by the rest of the library and they can be used everythere else. As the macro functions have no type, they are compatible with any data type.+Bitwise operations library contains a set of macro functions to do common bit manipulation operations. They are used by the rest of the library and can be used everywhere else. As the macro-functions have no type, they are compatible with any data type.
  
-Bit index is used to specify the bit in the binary number. Indexes are counted from zero, where zero represents the least significant bit (LSB). For example, 8-bit number have 8 bits with indexes from 0 to 7 and 16-bit number have 16 bits with indexes from 0 to 15.+Bit index is used to specify the bit in the binary number. Indexes are counted from zero, where zero represents the least significant bit (LSB). For example, an 8-bit number has 8 bits with indexes from 0 to 7 and 16-bit number has 16 bits with indexes from 0 to 15.
  
-===== Funktsioonid =====+===== Functions =====
  
   * **//bit_mask(bit)//** \\   * **//bit_mask(bit)//** \\
Line 60: Line 60:
 } }
 </code> </code>
 +
 +===== Source =====
 +
 +The following is a shortened version of the bitwise operations library source code.
 +
 +<code c>
 +//
 +// Functions for handling bits.
 +//
 +#define bit_mask(bit)            (1 << (bit))
 +#define bit_set(value, bit)      value |= bit_mask(bit)
 +#define bit_clear(value, bit)    value &= ~bit_mask(bit)
 +#define bit_invert(value, bit)   value ^= bit_mask(bit)
 +#define bit_is_set(value, bit)   ((value) & (bit_mask(bit)))
 +#define bit_is_clear(value, bit) (!((value) & (bit_mask(bit))))
 +#define bit_set_to(v, b, x) v = ((x) ? (v | bit_mask(b)) : (v & ~bit_mask(b)))
 +
 +//
 +// Functions for handling bit masks.
 +//
 +#define bitmask_set(value, bitMask)     value |= (bitMask)
 +#define bitmask_clear(value, bitMask)   value &= ~(bitMask)
 +#define bitmask_invert(value, bitMask)  value ^= (bitMask)
 +#define bitmask_set_to(v, m, x)         v = ((x) ? (v | (m)) : (v & ~(m))) 
 +#define bitmask_is_set(value, bitMask)  ((value) & (bitMask))
 +</code>
 +
en/software/homelab/library/bit.1268044749.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0