Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method · added in Ruby 4.1
String#bitwise_not
bitwise_not → string
string.c
View on GitHub ↗
static VALUE
rb_str_bitwise_not(VALUE str)
{
rb_len_t len = RSTRING_LEN(str);
VALUE result = str_bitwise_result(str);
str_bitwise_not((unsigned char *)RSTRING_PTR(result),
(const unsigned char *)RSTRING_PTR(str), len);
return result;
}
Returns a new string whose bytes are the bitwise complement of self:
Example
"\x00\xAA".bitwise_not # => "\xFF\x55"
The returned string has BINARY encoding.
Ruby version changes
-
4.1
-
Basic bit operations are added.
String#bit_get,String#bit_set?,String#bit_set,String#bit_clear,String#bit_flipandString#bit_counthandle individual bits, andString#bitwise_not,String#bitwise_and,String#bitwise_or,String#bitwise_xor(with their!variants) handle whole strings. [Feature #22118]
-