D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Integer
/
Filename :
bit_length-i.ri
back
Copy
U:RDoc::AnyMethod[iI"bit_length:ETI"Integer#bit_length;TF:publico:RDoc::Markup::Document:@parts[ o:RDoc::Markup::Paragraph; [ I"8Returns the number of bits of the value of +self+, ;TI"8which is the bit position of the highest-order bit ;TI")that is different from the sign bit ;TI";(where the least significant bit has bit position 1). ;TI"?If there is no such bit (zero or minus one), returns zero.;To:RDoc::Markup::BlankLine o; ; [I"KThis method returns <tt>ceil(log2(self < 0 ? -self : self + 1))</tt>>.;T@o:RDoc::Markup::Verbatim; [I")(-2**1000-1).bit_length # => 1001 ;TI")(-2**1000).bit_length # => 1000 ;TI")(-2**1000+1).bit_length # => 1000 ;TI"'(-2**12-1).bit_length # => 13 ;TI"'(-2**12).bit_length # => 12 ;TI"'(-2**12+1).bit_length # => 12 ;TI"&-0x101.bit_length # => 9 ;TI"&-0x100.bit_length # => 8 ;TI"&-0xff.bit_length # => 8 ;TI"&-2.bit_length # => 1 ;TI"&-1.bit_length # => 0 ;TI"&0.bit_length # => 0 ;TI"&1.bit_length # => 1 ;TI"&0xff.bit_length # => 8 ;TI"&0x100.bit_length # => 9 ;TI"'(2**12-1).bit_length # => 12 ;TI"'(2**12).bit_length # => 13 ;TI"'(2**12+1).bit_length # => 13 ;TI")(2**1000-1).bit_length # => 1000 ;TI")(2**1000).bit_length # => 1001 ;TI")(2**1000+1).bit_length # => 1001 ;T:@format0o; ; [I"For \Integer _n_, ;TI">this method can be used to detect overflow in Array#pack:;T@o;; [ I"if n.bit_length < 32 ;TI"$ [n].pack('l') # No overflow. ;TI" else ;TI" raise 'Overflow' ;TI"end;T; 0: @fileI"numeric.rb;T:0@omit_headings_from_table_of_contents_below0I"bit_length -> integer ;T0[ I"();T@8FI"Integer;TcRDoc::NormalClass00