+
Point of view
All features
class BIT_STRING
Summary
Long and very long bit sequences. An INTEGER index can be used to access each bit of the sequence. The leftmost bit has index 1 and the rightmost bit has index count.
For short bit sequences (less or equal to 32 or 64), also consider to use basic INTEGER_N type.
Direct parents
Inherit list: TRAVERSABLE
Insert list: PLATFORM
Class invariant
Overview
Creation features
{ANY}
  • make (n: INTEGER_32)
    Make bit sequence of n bits.
  • from_string (model: STRING)
    Create or set Current using model which is supposed to be a sequence of mixed 0 or 1 characters.
Features
{}
{BIT_STRING}
{ANY}
Rotating and shifting:
{ANY}
Bitwise Logical Operators:
{ANY}
  • infix "and" (other: BIT_STRING): BIT_STRING
    Bitwise and of Current with other
  • infix "implies" (other: BIT_STRING): BIT_STRING
    Bitwise implication of Current with other
  • prefix "not": BIT_STRING
    Bitwise not of Current.
  • infix "or" (other: BIT_STRING): BIT_STRING
    Bitwise or of Current with other.
  • infix "xor" (other: BIT_STRING): BIT_STRING
    Bitwise xor of Current with other
  • and_mask (other: BIT_STRING)
    Apply bitwise and mask of other onto Current.
  • implies_mask (other: BIT_STRING)
    Apply bitwise implies mask of other.
  • or_mask (other: BIT_STRING)
    Apply bitwise or mask of other onto Current.
  • xor_mask (other: BIT_STRING)
    Apply bitwise xor mask of other onto Current
  • invert
    Invert Current bit-per-bit.
Conversions:
{ANY}
Others:
{ANY}
Other features:
{ANY}
{}
{ANY}
Other features:
{ANY}
Agent-based features:
{ANY}
{ANY}
{}
Agent-based features:
{ANY}
{}
Maximum:
{}
Minimum:
{}
Bits:
{}
word_size: INTEGER_8
is 32
constant attribute
{}
size of words in storage
word_limit: INTEGER_8
is 31
constant attribute
{}
word_size - 1
writable attribute
The storage area.
Bits are stored in the usual way (as they are printed). Padding of the last word is done using 0 on the right.
count: INTEGER_32
writable attribute
{ANY}
Number of bits in the sequence.
ensure
  • Result >= 0
lower: INTEGER_32
is 1
constant attribute
{ANY}
Minimum index.
See also upper, valid_index, item.
upper: INTEGER_32
effective function
{ANY}
Maximum index.
See also lower, valid_index, item.
is_empty: BOOLEAN
effective function
{ANY}
Is the hoard empty ?
See also count.
ensure
  • definition: Result = count = 0
make (n: INTEGER_32)
effective procedure
{ANY}
Make bit sequence of n bits.
All bits are set to False.
require
  • n > 0
ensure
from_string (model: STRING)
effective procedure
{ANY}
Create or set Current using model which is supposed to be a sequence of mixed 0 or 1 characters.
require
  • model.is_bit
valid_index (idx: INTEGER_32): BOOLEAN
effective function
{ANY}
True when index is valid (ie. inside actual bounds of the bit sequence).
ensure
  • definition: Result = lower <= idx and idx <= upper
item (idx: INTEGER_32): BOOLEAN
effective function
{ANY}
True if idx-th bit is 1, False otherwise.
require
  • valid_index(idx)
first: BOOLEAN
effective function
{ANY}
The very first item.
See also last, item.
require
  • not is_empty
ensure
  • definition: Result = item(lower)
last: BOOLEAN
effective function
{ANY}
The last item.
See also first, item.
require
  • not is_empty
ensure
  • definition: Result = item(upper)
put (value: BOOLEAN, idx: INTEGER_32)
effective procedure
{ANY}
Set bit idx to 1 if value is True, 0 otherwise.
require ensure
put_1 (idx: INTEGER_32)
effective procedure
{ANY}
Set bit idx to 1.
require ensure
put_0 (idx: INTEGER_32)
effective procedure
{ANY}
Set bit idx to 0.
require ensure
shift_by (n: INTEGER_32)
effective procedure
{ANY}
Shift n-bits.
n > 0 : shift right, n < 0 : shift left, n = 0 : do nothing. Falling bits are lost and entering bits are 0.
ensure
shift_left_by (n: INTEGER_32)
effective procedure
{ANY}
Shift left by n bits.
Falling bits are lost and entering bits are 0.
require
  • n >= 0
shift_right_by (n: INTEGER_32)
effective procedure
{ANY}
Shift right by n bits.
Falling bits are lost and entering bits are 0.
require
  • n >= 0
rotate_by (n: INTEGER_32)
effective procedure
{ANY}
Rotate by n bits.
n > 0 : Rotate right, n < 0 : Rotate left, n = 0 : do nothing.
rotate_left_by (n: INTEGER_32)
effective procedure
{ANY}
Rotate left by n bits.
require
  • n >= 0
rotate_right_by (n: INTEGER_32)
effective procedure
{ANY}
Rotate right by n bits.
require
  • n >= 0
infix "^" (s: INTEGER_32): BIT_STRING
effective function
{ANY}
Sequence shifted by s positions (positive s shifts right, negative left; bits falling off the sequence's bounds are lost).
See also infix "|>>" and infix "|<<".
require
infix "|>>" (s: INTEGER_32): BIT_STRING
effective function
{ANY}
Sequence shifted right by s positions.
Same as infix "^" when s is positive (may run a little bit faster).
require
  • s > 0
infix "|<<" (s: INTEGER_32): BIT_STRING
effective function
{ANY}
Sequence shifted left by s positions.
Same as infix "^" when s is negative (may run a little bit faster.
require
  • s > 0
infix "#" (s: INTEGER_32): BIT_STRING
effective function
{ANY}
Sequence rotated by s positions (positive right, negative left).
require
infix "#>>" (s: INTEGER_32): BIT_STRING
effective function
{ANY}
Sequence rotated by s positions right.
require
infix "#<<" (s: INTEGER_32): BIT_STRING
effective function
{ANY}
Sequence rotated by s positions left.
require
infix "and" (other: BIT_STRING): BIT_STRING
effective function
{ANY}
Bitwise and of Current with other
require ensure
infix "implies" (other: BIT_STRING): BIT_STRING
effective function
{ANY}
Bitwise implication of Current with other
require ensure
prefix "not": BIT_STRING
effective function
{ANY}
Bitwise not of Current.
ensure
infix "or" (other: BIT_STRING): BIT_STRING
effective function
{ANY}
Bitwise or of Current with other.
require ensure
infix "xor" (other: BIT_STRING): BIT_STRING
effective function
{ANY}
Bitwise xor of Current with other
require ensure
and_mask (other: BIT_STRING)
effective procedure
{ANY}
Apply bitwise and mask of other onto Current.
require
implies_mask (other: BIT_STRING)
effective procedure
{ANY}
Apply bitwise implies mask of other.
require
or_mask (other: BIT_STRING)
effective procedure
{ANY}
Apply bitwise or mask of other onto Current.
require
xor_mask (other: BIT_STRING)
effective procedure
{ANY}
Apply bitwise xor mask of other onto Current
require
invert
effective procedure
{ANY}
Invert Current bit-per-bit.
to_string: STRING
effective function
{ANY}
String representation of bit sequence.
A zero bit is mapped to '0', a one bit to '1'. Leftmost bit is at index 1 in the returned string.
Note: see append_in to save memory.
ensure
to_integer: INTEGER_32
effective function
{ANY}
The corresponding INTEGER value when count <= Integer_bits. No sign-extension when count < Integer_bits.
require
all_cleared: BOOLEAN
effective function
{ANY}
Are all bits set to 0?
all_default: BOOLEAN
effective function
{ANY}
Are all bits set to 0?
clear_all
effective procedure
{ANY}
Set all bits to 0
ensure
all_set: BOOLEAN
effective function
{ANY}
Are all bits set to 1?
set_all
effective procedure
{ANY}
Set all bits to 1
ensure
is_equal (other: BIT_STRING): BOOLEAN
effective function
{ANY}
Is other attached to an object considered equal to current object?
require
    • other /= Void
      • other /= Void
      • other /= Void
ensure
  • commutative: generating_type = other.generating_type implies Result = other.is_equal(Current)
copy (other: BIT_STRING)
effective procedure
{ANY}
Update current object using fields of object attached to other, so as to yield equal objects.
Note: you can't copy object from a different dynamic type.
require
    • not immutable
    • same_dynamic_type(other)
      • not immutable
      • same_dynamic_type(other)
      • not immutable
      • same_dynamic_type(other)
ensure
  • is_equal(other)
out_in_tagged_out_memory
effective procedure
{ANY}
Append terse printable representation of current object in tagged_out_memory
require
    • locked: tagged_out_locked
      • locked: tagged_out_locked
      • locked: tagged_out_locked
ensure
  • still_locked: tagged_out_locked
  • not_cleared: tagged_out_memory.count >= old tagged_out_memory.count
  • append_only: old tagged_out_memory.twin.is_equal(tagged_out_memory.substring(1, old tagged_out_memory.count))
append_in (str: STRING)
effective procedure
{ANY}
Append in str a viewable representation of Current.
set_from_string (model: STRING, offset: INTEGER_32)
effective procedure
{ANY}
Use the whole contents of model to reset range offset ..
offset + model.count - 1 of Current. Assume all characters of model are 0 or 1.
require ensure
new_iterator: ITERATOR[BOOLEAN]
effective function
{ANY}
ensure
  • Result /= Void
  • Result.generation = generation
basic_rotate_right (n: INTEGER_32)
effective procedure
{}
Rotate right by n bits.
|*** PR(02/11/2004) This is not yet optimized.
require
  • n.in_range(0, count - 1)
enumerate: ENUMERATE[E_]
effective function
{ANY}
get_new_iterator: ITERATOR[E_]
frozen
effective function
{ANY}
This feature is obsolete: Use `new_iterator' instead. This historical SmartEiffel feature is badly named.
for_each (action: PROCEDURE[TUPLE[TUPLE 1[E_]]])
effective procedure
{ANY}
Apply action to every item of Current.
See also for_all, exists, aggregate.
require
  • action /= Void
for_all (test: FUNCTION[TUPLE[TUPLE 1[E_]]]): BOOLEAN
effective function
{ANY}
Do all items satisfy test?
See also for_each, exists, aggregate.
require
  • test /= Void
exists (test: FUNCTION[TUPLE[TUPLE 1[E_]]]): BOOLEAN
effective function
{ANY}
Does at least one item satisfy test?
See also for_each, for_all, aggregate.
require
  • test /= Void
aggregate (action: FUNCTION[TUPLE[TUPLE 2[E_, E_], E_]], initial: E_): E_
effective function
{ANY}
Aggregate all the elements starting from the initial value.
See also for_each, for_all, exists.
require
  • action /= Void
generation: INTEGER_32
writable attribute
{ANY}
next_generation
effective procedure
{}
ensure
do_all (action: ROUTINE[TUPLE[TUPLE 1[E_]]])
frozen
effective procedure
{ANY}
Apply action to every item of Current.
This feature is obsolete: Use `for_each` instead. This feature is not secure because it accepts a FUNCTION, the result of which is lost.
_inline_agent1 (a: ROUTINE[TUPLE[TUPLE 1[E_]]], e: E_)
frozen
effective procedure
{}
Maximum_character_code: INTEGER_16
{}
Largest supported code for CHARACTER values.
ensure
  • meaningful: Result >= 127
Maximum_integer_8: INTEGER_8
is 127
constant attribute
{}
Largest supported value of type INTEGER_8.
Maximum_integer_16: INTEGER_16
is 32767
constant attribute
{}
Largest supported value of type INTEGER_16.
Maximum_integer: INTEGER_32
is 2147483647
constant attribute
{}
Largest supported value of type INTEGER/INTEGER_32.
Maximum_integer_32: INTEGER_32
is 2147483647
constant attribute
{}
Largest supported value of type INTEGER/INTEGER_32.
Maximum_integer_64: INTEGER_64
is 9223372036854775807
constant attribute
{}
Largest supported value of type INTEGER_64.
Maximum_real_32: REAL_32
is {REAL_32 3.4028234663852885981170418348451692544e+38}
constant attribute
{}
Largest non-special (no NaNs nor infinity) supported value of type REAL_32.
Maximum_real: REAL_64
{}
Largest non-special (no NaNs nor infinity) supported value of type REAL.
Just to give an idea of this value: 1.79769313486231570....e+308
Maximum_real_64: REAL_64
{}
Largest non-special (no NaNs nor infinity) supported value of type REAL.
Just to give an idea of this value: 1.79769313486231570....e+308
Maximum_real_80: REAL_EXTENDED
{}
Largest supported value of type REAL_80.
ensure
Minimum_character_code: INTEGER_16
{}
Smallest supported code for CHARACTER values.
ensure
  • meaningful: Result <= 0
Minimum_integer_8: INTEGER_8
is -128
constant attribute
{}
Smallest supported value of type INTEGER_8.
Minimum_integer_16: INTEGER_16
is -32768
constant attribute
{}
Smallest supported value of type INTEGER_16.
Minimum_integer: INTEGER_32
is -2147483648
constant attribute
{}
Smallest supported value of type INTEGER/INTEGER_32.
Minimum_integer_32: INTEGER_32
is -2147483648
constant attribute
{}
Smallest supported value of type INTEGER/INTEGER_32.
Minimum_integer_64: INTEGER_64
is -9223372036854775808
constant attribute
{}
Smallest supported value of type INTEGER_64.
Minimum_real_32: REAL_32
is {REAL_32 -3.40282346638528859811704183484516925440e+38}
constant attribute
{}
Smallest non-special (no NaNs nor infinity) supported value of type REAL_32.
Minimum_real: REAL_64
{}
Smallest non-special (no NaNs nor infinity) supported value of type REAL.
Just to give an idea of this value: -1.79769313486231570....e+308
Minimum_real_64: REAL_64
{}
Smallest non-special (no NaNs nor infinity) supported value of type REAL.
Just to give an idea of this value: -1.79769313486231570....e+308
Minimum_real_80: REAL_64
{}
Smallest supported value of type REAL_80.
ensure
  • meaningful: Result <= 0.0
Boolean_bits: INTEGER_32
{}
Number of bits in a value of type BOOLEAN.
ensure
  • meaningful: Result >= 1
Character_bits: INTEGER_32
{}
Number of bits in a value of type CHARACTER.
ensure
Integer_bits: INTEGER_32
{}
Number of bits in a value of type INTEGER.
ensure
  • integer_definition: Result = 32
Real_bits: INTEGER_32
is 64
constant attribute
{}
Number of bits in a value of type REAL.
Pointer_bits: INTEGER_32
{}
Number of bits in a value of type POINTER.