This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:software:homelab:library:bit [2010/02/08 12:51] – mikk.leini | en:software:homelab:library:bit [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Bitwise | + | ====== Bitwise |
- | Bitioperatsioonide teek on üldkasutatav makrofunktsioonide kogum tüüpiliste bititehete teostamiseks. Seda kasutavad kõik teised teegid, kuid seda võib kasutada ükskõik milliste registrite või andmete puhul, sest makrofunktsioonidel pole kindlat andmetüüpi. Funktsioonid 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 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. |
- | Bitiindeksiks loetakse biti järjekorranumbrit, alustades kõige vähemtähtsast (inglise keeles //least significant bit//, lühend | + | 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 a 16-bit number has 16 bits with indexes from 0 to 15. |
- | ===== Funktsioonid | + | ===== Functions |
* **// | * **// | ||
- | | + | |
- | * //bit// - Bitiindeks. | + | * //bit// - Bit index. |
- | * Tagastab bitimaski. | + | * Returns bit mask. |
* **// | * **// | ||
- | | + | |
- | * //value// - Muutuja. | + | * //value// - Variable. |
- | * //bit// - Bitiindeks. | + | * //bit// - Bit index. |
* **// | * **// | ||
- | | + | |
- | * //value// - Muutuja. | + | * //value// - Variable. |
- | * //bit// - Bitiindeks. | + | * //bit// - Bit index. |
* **// | * **// | ||
- | | + | |
- | * //value// - Muutuja. | + | * //value// - Variable. |
- | * //bit// - Bitiindeks. | + | * //bit// - Bit index. |
- | * //state// - Tõeväärtus | + | * //state// - State (// |
* **// | * **// | ||
- | | + | |
- | * //value// - Muutuja. | + | * //value// - Variable. |
- | * //bit// - Bitiindeks. | + | * //bit// - Bit index. |
* **// | * **// | ||
- | | + | |
- | * //value// - Muutuja. | + | * //value// - Variable. |
- | * //bit// - Bitiindeks. | + | * //bit// - Bit index. |
- | * Tagastab tõeväärtuse | + | * Returns boolean value // |
* **// | * **// | ||
- | | + | |
- | * //value// - Muutuja. | + | * //value// - Variable. |
- | * //bit// - Bitiindeks. | + | * //bit// - Bit index. |
- | * Tagastab tõeväärtuse | + | * Returns boolean value // |
- | ===== Näide | + | ===== Example |
- | Muutujas | + | Setting up a third bit in the 8-bit variable |
<code c> | <code c> | ||
Line 60: | Line 60: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ===== Source ===== | ||
+ | |||
+ | The following is a shortened version of the bitwise operations library source code. | ||
+ | |||
+ | <code c> | ||
+ | // | ||
+ | // Functions for handling bits. | ||
+ | // | ||
+ | #define bit_mask(bit) | ||
+ | #define bit_set(value, | ||
+ | #define bit_clear(value, | ||
+ | #define bit_invert(value, | ||
+ | #define bit_is_set(value, | ||
+ | #define bit_is_clear(value, | ||
+ | #define bit_set_to(v, | ||
+ | |||
+ | // | ||
+ | // Functions for handling bit masks. | ||
+ | // | ||
+ | #define bitmask_set(value, | ||
+ | #define bitmask_clear(value, | ||
+ | #define bitmask_invert(value, | ||
+ | #define bitmask_set_to(v, | ||
+ | #define bitmask_is_set(value, | ||
+ | </ | ||
+ |