AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

0b0111 in Delphi-Sprache

Ein Thema von StTüff · begonnen am 6. Nov 2003 · letzter Beitrag vom 7. Nov 2003
Antwort Antwort
scp

Registriert seit: 31. Okt 2003
1.120 Beiträge
 
Delphi 7 Personal
 
#1

Re: 0b0111 in Delphi-Sprache

  Alt 6. Nov 2003, 20:26
Eine Alternative:

Delphi-Quellcode:
function ByteToBinWord(AByte : Byte) : LongWord;
begin
  result := AByte and $01;

  result := result + (((AByte shr 1) and $01) * 10);
  result := result + (((AByte shr 2) and $01) * 100);
  result := result + (((AByte shr 3) and $01) * 1000);
  result := result + (((AByte shr 4) and $01) * 10000);
  result := result + (((AByte shr 5) and $01) * 100000);
  result := result + (((AByte shr 6) and $01) * 1000000);
  result := result + (((AByte shr 7) and $01) * 10000000);
end;

function BinWordToByte(ABinWord : LongWord) : Byte;
begin
  result := 0;
  result := result + ((ABinWord div 10000000) shl 7); ABinWord := ABinWord mod 10000000;
  result := result + ((ABinWord div 1000000) shl 6); ABinWord := ABinWord mod 1000000;
  result := result + ((ABinWord div 100000) shl 5); ABinWord := ABinWord mod 100000;
  result := result + ((ABinWord div 10000) shl 4); ABinWord := ABinWord mod 10000;
  result := result + ((ABinWord div 1000) shl 3); ABinWord := ABinWord mod 1000;
  result := result + ((ABinWord div 100) shl 2); ABinWord := ABinWord mod 100;
  result := result + ((ABinWord div 10) shl 1); ABinWord := ABinWord mod 10;
  result := result + ABinWord;
end;

function ByteToBinStr(AByte : Byte) : String;
begin
  result := IntToStr(ByteToBinWord(AByte));
  while (length(Result) < 8) do
    result := '0' + result;
end;

function BinStrToByte(ABinStr : String) : Byte;
begin
  result := BinWordToByte(StrToIntDef(ABinStr, 0));
end;
So kann man 8 Nullen und Einsen in einen LongWord packen und wieder als Byte oder String zurückholen.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:50 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz