Das Open-Control-Projekt - Die Alternative zur C-Control-I


Das Forum zur C-Control-1
Welche C-Control-Varianten existieren?
Übersicht - Suchen - Neueste 50 Beiträge - Neuer Beitrag - Login - Registrieren
INFO - FAQ - CC2-Forum - CCPro-Forum 

 Re: Parity Kategorie: Programmierung Basic (von ManfredW, Homepage - 19.11.2006 19:47)
 Als Antwort auf Parity von Waly - 19.11.2006 0:15
> Ganz dumme Frage:
>
> Ich hab eine byte Variable. Zu der brauche ich das passende Parity-Bit (Gerade)
> Wie komme ich möglichst ohne viel Rechenzeit an diesen Wert ?
>
> Gruß,
> Markus

Hallo,
ich würde eine der folgenden Lösungen nehmen. Für Basic++ sinngemäß
MfG ManfredW

define Testbyte byte
define parity Bit [ ]
define Bits byte  'Bit0 bis Bit7
define Bit0 Bit [ ]
define Bit1 Bit [ ]
usw.
1. Möglichkeit

Bits = Testbyte
Parity = ON 'Vorbesetzung even
if Bit0  then Parity = not Parity
if Bit1  then Parity = not Parity
if Bit2  then Parity = not Parity
if Bit3  then Parity = not Parity
if Bit4  then Parity = not Parity
if Bit5  then Parity = not Parity
if Bit6  then Parity = not Parity
if Bit7  then Parity = not Parity

'--------------------------------
2. Möglichkeit (vermutlich schneller)

Bits = Testbyte
Parity = ON 'Vorbesetzung even
Parity = Bit0 XOR Parity
Parity = Bit1 XOR Parity
Parity = Bit2 XOR Parity
Parity = Bit3 XOR Parity
Parity = Bit4 XOR Parity
Parity = Bit5 XOR Parity
Parity = Bit6 XOR Parity
Parity = Bit7 XOR Parity ' 01  11  00  10
' Beispiel Bit7   Parity =     1    0    0   1

Meine Homepage: http://manfred.wilzeck.de

 Antwort schreiben

Bisherige Antworten: