AGB  ·  Datenschutz  ·  Impressum  







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

Index vom x-tem gesetztem Bit

Ein Thema von calibra301 · begonnen am 1. Jun 2020 · letzter Beitrag vom 16. Jun 2020
 
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.326 Beiträge
 
Delphi 12 Athens
 
#25

AW: Index vom x-tem gesetztem Bit

  Alt 16. Jun 2020, 17:13
Delphi-Quellcode:
if byte1 and 1 = 1 then
if byte1 and 2 = 2 then
if byte1 and 4 = 4 then
if byte1 and 8 = 8 then
...

// keine Redundanzen: erstmal die unnötig doppelten Zahlen entfernt

if byte1 and 1 <> 0 then
if byte1 and 2 <> 0 then
if byte1 and 4 <> 0 then
if byte1 and 8 <> 0 then
...

// und dann gibt es noch viele andere Wege, um das letzte/rechte Bit zu prüfen

if Odd(byte1 {shr 0}) then // if (byte1 {shr 0}) and 1 <> 0 then
if Odd(byte1 shr 1) then // if (byte1 shr 1) and 1 <> 0 then
if Odd(byte1 shr 2) then // if (byte1 shr 2) and 1 <> 0 then
if Odd(byte1 shr 3) then // if (byte1 shr 3) and 1 <> 0 then
...

// oder man nutzt direkt vorhandene Bit-Operationen

//type TByteSet = set of 0..7;
if 1 in TByteSet(byte1) then
if 2 in TByteSet(byte1) then
if 3 in TByteSet(byte1) then
...

// bzw. direkt die Variable "byte1" als diesen Typ definieren, ohne ständige Konvertierung
Gerade bei Bitmasken arbeite ich gern Hexadezimal, anstatt Dezimal. (binäre Zahlen kann Delphi leider nicht)
$01 = 1
$02 = 2
$04 = 4
$08 = 8
$10 = 16
$20 = 32
$40 = 64
$80 = 128
Ein Therapeut entspricht 1024 Gigapeut.

Geändert von himitsu (16. Jun 2020 um 18:34 Uhr)
  Mit Zitat antworten Zitat
 


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 03:08 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