Nimm eine Word Variable und ein Byte Array
Dann weise dem Word die Erste Variable zu,
schiebe das Word um 8-Bits nach oben (left)
und füge Deinen zweiten Wert hinzu:
Ist zwar etwas an Deinem Ziel vorbei aberCode:DIM W_Var as word DIM B_Array(2) as byte W_Var = &B0000000000000000 ' = 0 (Binäre Schreibweise) B_Array(1) = 9 ' = 00001001 B_Array(2) = 1 ' = 00000001 print bin(B_Array(1)) print bin(B_Array(2)) W_Var = B_Array(1) ' = 0000000000001001 = 9 print bin(W_Var) ' dieses um 8-Bit nach links (in das obere Byte) schieben Shift W_Var, Left , 8 ' = 0000100100000000 = 2304 print bin(W_Var) ' und den zweiten Wert hinzu Odern (addieren) W_Var = W_Var Or B_Array(2) ' = 0000100100000001 = 2305 print bin(W_Var) End
Du kannst ja auch nur um vier Bit nach links verschieben
dann bekommst Du aber immer noch nur vier Werte in ein Word.
Der Vorteil ligt darin, dass es schneller geht (Rechenzeit) und dass Du dies logisch abfragen kannst.
Code:DIM W_Var as word DIM W_Temp as word DIM B_Array(4) as byte W_Var = &B0000000000000000 ' = 0 (Binäre Schreibweise) B_Array(1) = 9 ' = 00001001 B_Array(2) = 1 ' = 00000001 B_Array(3) = 1 ' = 00000001 B_Array(4) = 1 ' = 00000001 print bin(B_Array(1)) print bin(B_Array(2)) print bin(B_Array(3)) print bin(B_Array(4)) 'Sicherheitshalber die oberen 4-Bit ausmaskieren um ein versehentliches Überschreiben zu verhindern. B_Array(1) = B_Array(1) AND &B00001111 B_Array(2) = B_Array(2) AND &B00001111 B_Array(3) = B_Array(3) AND &B00001111 B_Array(4) = B_Array(4) AND &B00001111 W_Var = B_Array(1) ' = 0000000000001001 ' dieses um 4-Bit nach links schieben Shift W_Var, Left , 4 ' 'dann die vier Bit hinzu Odern W_Var = W_Var OR B_Array(2) ' = 0000000010010001 ' wieder um vier Bit nach links Shift W_Var, Left , 4 ' ' wieder vier Bit hinzu W_Var = W_Var OR B_Array(3) ' = 0000100100010001 ' wieder um vier Bit nach links Shift W_Var, Left , 4 ' ' wieder vier Bit hinzu W_Var = W_Var OR B_Array(4) ' = 1001000100010001 print bin(W_Var) ' 4. Zahl Abfragen: W_Temp = W_Var AND &B1111000000000000 Shift W_Temp, right,12 Print W_Temp ' = 9 End







Zitieren

Lesezeichen