bitFlip {bitops} R Documentation

## Binary Flip (Not) Operator

### Description

The binary flip (‘not’, R's `!`) operator, `bitFlip(a, w)`, “flips every bit” of `a` up to the `w`-th bit.

### Usage

```bitFlip(a, bitWidth = 32)
```

### Arguments

 `a` numeric vector. `bitWidth` scalar integer between 0 and 32.

### Value

(“binary”) numeric vector of the same length as `a` masked with (2^`bitWidth`)-1. `NA` is returned for any value of `a` that is not finite or whose magnitude is greater or equal to 2^{32}.

### Note

`bitFlip(a, w)` is an “involution”, i.e. it is its own inverse – when `a` is in \{0, 1, .., 2^{32}-1\}. Notably, negative values `a` are equivalent to their values in the above range, see also `bitUnique()` in the ‘Examples’.

### Author(s)

Steve Dutky

`bitShiftL`, `bitXor`, etc.

### Examples

```bitFlip(0:5)
##
bitUnique <- function(x) bitFlip(bitFlip(x)) # "identity" when x in  0:(2^32-1)
bitUnique(  0:16 ) # identical (well, double precision)
bitUnique(-(1:16)) # 4294967295 ...
stopifnot(
identical(bitUnique(-(1:16)), 2^32 -(1:16)),
bitFlip(-1) == 0,
bitFlip(0 ) == 2^32 - 1,
bitFlip(0, bitWidth=8) == 255
)
```

[Package bitops version 1.0-7 Index]
{"ft_lang_label":"__label__en","ft_lang_prob":0.5695832,"math_prob":0.986748,"size":959,"snap":"2021-43-2021-49","text_gpt3_token_len":333,"char_repetition_ratio":0.1382199,"word_repetition_ratio":0.0,"special_character_ratio":0.3826903,"punctuation_ratio":0.18932039,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99550474,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-06T15:24:17Z\",\"WARC-Record-ID\":\"<urn:uuid:a1f6b51d-c4d0-4663-8901-0629338ff389>\",\"Content-Length\":\"3012\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8e6a2501-8f5a-486b-b574-8c10b0904657>\",\"WARC-Concurrent-To\":\"<urn:uuid:492fb667-a9f2-486e-9c25-1d97a7562129>\",\"WARC-IP-Address\":\"137.208.57.46\",\"WARC-Target-URI\":\"https://search.r-project.org/CRAN/refmans/bitops/html/bitFlip.html\",\"WARC-Payload-Digest\":\"sha1:ETGXYAT7HKJFYKGO6GAAQPNDOJVNLCPP\",\"WARC-Block-Digest\":\"sha1:IU4MDNECHZUYXHAHTBHDKB7XJ6V6A7HT\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964363301.3_warc_CC-MAIN-20211206133552-20211206163552-00478.warc.gz\"}"}