Konuyu Oyla:
  • Derecelendirme: 5/5 - 2 oy
  • 1
  • 2
  • 3
  • 4
  • 5
Byte & Set Of
#11
program Bitter;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

type
  TByteSet = set of 0..7;

function SetBit(Bitler: TByteSet): Byte;
begin
  TByteSet(Result) := Bitler;
end;

function GetBit(aBayt: Byte): TByteSet;
begin
  Result := TByteSet(aBayt);
end;

function BitToStr(aBayt: Byte): String;
var
  I: Integer;
begin
  Result := '0x';                           { aslında bir if...  }
  for I := 0 to 7 do Result := Result + Byte( I in GetBit(aBayt) ).ToString;
end;

var
  Veri: Byte;
begin
  Veri := SetBit([1,3,5,7]);   Writeln(Veri.ToString + ' - ' + BitToStr(Veri) );
  Veri := SetBit([0,2,4,6]);   Writeln(Veri.ToString + ' - ' + BitToStr(Veri) );
  Veri := SetBit([1,2,3,4]);   Writeln(Veri.ToString + ' - ' + BitToStr(Veri) );
  readln;
end.
YouTube Delphi Tips
"Mantıklı adam kendini dünyaya uyarlar; mantıksız adam ise dünyayı kendine uydurmakta inat eder. Bu nedenle, tüm ilerleme o inatçı adama bağlıdır." - George Bernard Shaw
WWW
Cevapla




Konuyu Okuyanlar: 1 Ziyaretçi