diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-06-26 13:06:47 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-06-26 13:06:47 -0400 |
| commit | 8a4d5dc57b14e7c947c25970bb4d4f4ef91450f4 (patch) | |
| tree | e36042760c7c22d5a08777939484c06830d73404 /api/integers.yaml | |
| parent | c2653404944dbd5a6f737877f0bad6fd1de018f1 (diff) | |
Add get_bit() method for Ints and Bytes
Diffstat (limited to 'api/integers.yaml')
| -rw-r--r-- | api/integers.yaml | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/api/integers.yaml b/api/integers.yaml index f927c75f..a91a21ce 100644 --- a/api/integers.yaml +++ b/api/integers.yaml @@ -81,7 +81,41 @@ Int.factorial: example: | >> (10).factorial() = 3628800 - + +Int.get_bit: + short: check whether a bit is set + description: > + In the binary representation of an integer, check whether a given bit index + is set to 1 or not. + note: > + For fixed-size integers, the bit index must be between 1 and the number of + bits in that integer (i.e. 1-64 for `Int64`). For `Int`, the bit index must + be between 1 and `Int64.max`. Values outside this range will produce a + runtime error. + return: + type: 'Bool' + description: > + Whether or not the given bit index is set to 1 in the binary + representation of the integer. + args: + i: + type: 'Int' + description: > + The integer whose bits are being inspected. + bit_index: + type: 'Int' + description: > + The index of the bit to check (1-indexed). + example: | + >> (6).get_bit(1) + = no + >> (6).get_bit(2) + = yes + >> (6).get_bit(3) + = yes + >> (6).get_bit(4) + = no + Int.hex: short: convert to hexidecimal description: > |
