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/02/08 12:51] 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 ======
  
-Bitioperatsioonide teek on üldkasutatav makrofunktsioonide kogum tüüpiliste bititehete teostamiseksSeda kasutavad kõik teised teegid, kuid seda võib kasutada ükskõik milliste registrite või andmete puhul, sest makrofunktsioonidel pole kindlat andmetüüpiFunktsioonid sobivad nii 8-, 16- kui ka 32-bitiste muutujate ning registrite jaoks.+Bitwise operations library contains a set of macro functions to do common bit manipulation operationsThey are used by the rest of the library and can be used everywhere elseAs the macro-functions have no typethey are compatible with any data type.
  
-Bitiindeksiks loetakse biti järjekorranumbritalustades kõige vähemtähtsast (inglise keeles //least significant bit//, lühend LSB). Loendamine algab nullist. 8-bitiste arvude puhul on bitiindeksi väärtus 0-716-bitiste puhul 0-15 ja 32-bitiste puhul 0-31.+Bit index is used to specify the bit in the binary number. Indexes are counted from zerowhere zero represents the least significant bit (LSB). For example, an 8-bit number has 8 bits with indexes from to and a 16-bit number has 16 bits with indexes from to 15.
  
-===== Funktsioonid =====+===== Functions =====
  
   * **//bit_mask(bit)//** \\   * **//bit_mask(bit)//** \\
-    Bitiindeksi teisendamine bitimaskiksParameetrid+    Bit index to bit mask convertingParameters
-    * //bit// - Bitiindeks+    * //bit// - Bit index
-    * Tagastab bitimaski.+    * Returns bit mask.
  
   * **//bit_set(value, bit)//** \\   * **//bit_set(value, bit)//** \\
-    Muutujas kindla biti kõrgeks seadmineParameetrid+    Sets a specified bit in the variableParameters
-    * //value// - Muutuja+    * //value// - Variable
-    * //bit// - Bitiindeks.+    * //bit// - Bit index.
  
   * **//bit_clear(value, bit)//** \\   * **//bit_clear(value, bit)//** \\
-    Muutujas kindla biti madalaks seadmineParameetrid+    Clears a specified bit in the variableParameters
-    * //value// - Muutuja+    * //value// - Variable
-    * //bit// - Bitiindeks.+    * //bit// - Bit index.
  
   * **//bit_set_to(value, bit, state)//** \\   * **//bit_set_to(value, bit, state)//** \\
-    Muutujas kindla biti soovitud olekusse seadmineParameetrid+    Set a specified bit in the variable to desired stateParameters
-    * //value// - Muutuja+    * //value// - Variable
-    * //bit// - Bitiindeks+    * //bit// - Bit index
-    * //state// - Tõeväärtus (//true// või //false//).+    * //state// - State (//true// or //false//).
  
   * **//bit_invert(value, bit)//** \\   * **//bit_invert(value, bit)//** \\
-    Muutujas kindla biti oleku ümberpööramine (madal kõrgeks ja vastupidi)Parameetrid+    Inverts a specified bit in the variableParameters
-    * //value// - Muutuja+    * //value// - Variable
-    * //bit// - Bitiindeks.+    * //bit// - Bit index.
  
   * **//bit_is_set(value, bit)//** \\   * **//bit_is_set(value, bit)//** \\
-    Väärtuse kindla biti kõrgeloleku kontrollParameetrid+    Checks whether a specified bit in the variable is set or notParameters
-    * //value// - Muutuja+    * //value// - Variable
-    * //bit// - Bitiindeks+    * //bit// - Bit index
-    * Tagastab tõeväärtuse //true//, kui bitt on kõrge ja //false//, kui bitt on madal.+    * Returns boolean value //true// when bit is set and //false// when bit is cleared.
  
   * **//bit_is_clear(value, bit)//** \\   * **//bit_is_clear(value, bit)//** \\
-    Väärtuse kindla biti madaloleku kontrollParameetrid+    Checks whether a specified bit in the variable is cleared or notParameters
-    * //value// - Muutuja+    * //value// - Variable
-    * //bit// - Bitiindeks+    * //bit// - Bit index
-    * Tagastab tõeväärtuse //true//, kui bitt on madal ja //false//, kui bitt on kõrge.+    * Returns boolean value //true// when bit is cleared and //false// when bit is set.
  
-===== Näide =====+===== Example =====
  
-Muutujas //b// kolmanda biti kõrgeks seadmine ja viimase ümberpööramine.+Setting up a third bit in the 8-bit variable //b// and inverting of the last one.
  
 <code c> <code c>
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.1265633486.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