type
BitSring = class
private
BitStr: byte;
function GetStr := BitStr;
function StrToByte(s: string): byte;
begin
Result := 0;
s := s.Left(8);
var p: byte := 1;
var len := s.Length;
for var i := len downto 1 do
begin
if s[i] = '1' then
Result += p;
p := p shl 1;
end
end;
public
property bit8: byte read GetStr;
constructor(st: string);
begin
BitStr := StrToByte(st);
end;
constructor(n: byte);
begin
BitStr := n;
end;
constructor;
begin
BitStr := 0;
end;
function Inv8 := new BitSring(not BitStr);
function Mod8 := new BitSring(not BitStr + 1);
function ToString: string; override;
begin
Result := '';
var n: byte := BitStr;
while n > 0 do
begin
Result := (if n mod 2 <> 0 then '1' else '0') + Result;
n := n shr 1
end;
var len := Result.Length;
if len < 8 then
Result := '0' * (8 - len) + Result
end;
end;
begin
var x := new BitSring(ReadString);
Println(x);
Println(x.Inv8);
Println(x.Mod8);
end.
Пример работы:
1011011
01011011
10100100
10100101