![]() |
Informationen aus Byte
Hallo
mein Problem leigt darin das ich den Datentyp Byte habe und nun wissen möchte ob an der letzten Stelle eine 1 oder eine 0 steht? Gibt es eine Möglichkeit die 1en und 0en als string auszugeben?? mfg Eisbar |
Re: Informationen aus Byte
Delphi-Quellcode:
function LastBitSet(b: Byte): Boolean;
begin Result:=Boolean(b and 1); end;
Delphi-Quellcode:
function BinToStr(b: Byte): String;
var I: Integer; begin setlength(result, 8); for I:=0 to 7 do result[I+1]:=chr((b shr (7-I)) and 1+48); end; |
Re: Informationen aus Byte
Moin Eisbar,
Delphi-Quellcode:
ShowMessage(IntToStr(bValue mod 2));
|
Re: Informationen aus Byte
Ein mod ist doch deutlich langsamer als ein and, oder?
|
Re: Informationen aus Byte
Hier mal eine Funktion aus der JCL (eine wahre Schatzkammer):
Delphi-Quellcode:
Mit TestBit kann man jedes Bit prüfen:
// Auszug aus Unit JclLogic.pas
// [url]http://sourceforge.net/projects/jcl[/url] const // Constants defining the number of bits in each Integer type BitsPerByte = 8; type TBitRange = Byte; function TestBit(const Value: Byte; const Bit: TBitRange): Boolean; begin Result := (Value and (1 shl (Bit mod BitsPerByte))) <> 0; end;
Delphi-Quellcode:
if TestBit(meinByte, 7) then ShowMessage('höchstwertiges Bit gesetzt');
|
Re: Informationen aus Byte
Vielen Dank
das funktioniert alles super. Jetzt habe ich aber ein weiteres Problem. Ich habe einen string der sieht ca. so aus: 01100100 und möchte diesen jetzt in einem Byte speichern. Wie sieht solch eine Funktion aus? |
Re: Informationen aus Byte
wie wärs mit: erst ins dezimal system umwandeln? such einfach bei google
gibt echt viele beispiele |
Re: Informationen aus Byte
Zitat:
![]() greetz Mike |
Re: Informationen aus Byte
Hallo,
Zitat:
Gruß Hawkeye |
Re: Informationen aus Byte
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:55 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-2025 by Thomas Breitkreuz