INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES

indexing

title: "Bit sequences of length `count%', with binary operations."
project: "Eiffel Kernel Library"
revision: "$Revision: 1.1 $"
copyright: "Copyright (C) 1996-2005 Object Tools Group"
license: "http://visual-eiffel.com/license"
cluster: kernel
expanded class BIT
inherit

ANY
redefine
out
end

PLATFORM
redefine
out
end
feature -- Measurement

count: INTEGER
feature -- Basic operations

infix "^" (i: INTEGER): like Current
-- Result of shifting bit sequence by 'i' positions
-- (Positive 'i' shifts right, negative 'i' shifts left
-- bits failling off the sequence's bounds are lost)

infix "#" (i: INTEGER): like Current
-- Result of rotating bit sequence by 'i' positions
-- (Positive 'i' rotates right, negative 'i' rotates left)

infix "and" (other: like Current): like Current
-- Bit-by-bit boolean conjunction with 'other'
require
other_exists: other /= void
conformance: other.count <= count

infix "or" (other: like Current): like Current
-- Bit-by-bit boolean disjunction with 'other'
require
other_exists: other /= void
conformance: other.count <= count

infix "xor" (other: like Current): like Current
-- Bit-by-bit exclusive or with 'other'
require
other_exists: other /= void
conformance: other.count <= count

infix "implies" (other: like Current): like Current
-- Bit-by-bit boolean implication of 'other'
require
other_exists: other /= void
conformance: other.count <= count

prefix "not": like Current
-- Bit-by-bit negation
feature -- Element change

put (value: BOOLEAN; i: INTEGER)
-- Set the 'i'-th bit to 1 if 'value' is True, 0 if False
require
inside_bounds: i >= 1 and then i <= count
ensure
value_inserted: item (i) = value
feature -- Access

item, infix "@" (i: INTEGER): BOOLEAN
-- 'i'-th bit
require
inside_bounds: i >= 1 and then i <= count
feature -- Convertion

to_string: STRING
-- String representation of bit sequence.
-- A zero bit is mapped to '0', a one bit
-- to '1'. item (1) is rightmost character in string
ensure
same_count: Result.count = count

from_string (s: STRING)
-- Fill sequence from string 's'.
-- 's' must contain '0' and '1' characters only
require
string_not_void: s /= void
not_too_long: s.count <= count

to_integer: INTEGER
-- Integer representation of bit sequence
require
not_too_long: count <= integer_bits

from_integer (i: INTEGER)
-- Fill sequence from integer 'i'
require
not_too_long: count <= integer_bits

out: STRING
-- New string containing printable representation of
-- current object
end -- class BIT

INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES