da musst du irgendwo nen Fehler reingehaun haben.
Code: Alles auswählen
a.b = 1
a << 7
Debug a
b.b = 1 << 7
Debug b
Code: Alles auswählen
a.b = 128
a >> 5
Debug a
Debug Hex( a , #PB_Byte )
Code: Alles auswählen
a.b = 1
a << 7
Debug a
b.b = 1 << 7
Debug b
Code: Alles auswählen
a.b = 128
a >> 5
Debug a
Debug Hex( a , #PB_Byte )
Code: Alles auswählen
;-TOP
; Kommentar : Bitshift and Rotation
; Author : mk-soft
; Second Author :
; Datei : .pb
; Version : 1.01
; Erstellt : 09.06.2007
; Geändert : 02.01.2009
;
; Compilermode :
;
; ***************************************************************************************
; Bitshift left roation
Procedure ROL32(value.l, count.l = 1)
!mov eax, dword [p.v_value]
!mov ecx, dword [p.v_count]
!rol eax, cl
ProcedureReturn
EndProcedure
; Bitshift rotation
Procedure ROR32(value.l, count.l = 1)
!mov eax, dword [p.v_value]
!mov ecx, dword [p.v_count]
!ror eax, cl
ProcedureReturn
EndProcedure
; Bitshift left shift
Procedure SHL8(value.b, count.l = 1)
!xor eax, eax
!mov al, byte [p.v_value]
!mov ecx, dword [p.v_count]
!shl al, cl
ProcedureReturn
EndProcedure
; Bitshift right shift
Procedure SHR8(value.b, count.l = 1)
!xor eax, eax
!mov al, byte [p.v_value]
!mov ecx, dword [p.v_count]
!shr al, cl
ProcedureReturn
EndProcedure
; Bitshift left shift
Procedure SHL16(value.w, count.l = 1)
!xor eax, eax
!mov ax, word [p.v_value]
!mov ecx, dword [p.v_count]
!shl ax, cl
ProcedureReturn
EndProcedure
; Bitshift right shift
Procedure SHR16(value.w, count.l = 1)
!xor eax, eax
!mov ax, word [p.v_value]
!mov ecx, dword [p.v_count]
!shr ax, cl
ProcedureReturn
EndProcedure
; Bitshift left shift
Procedure SHL32(value.l, count.l = 1)
!mov eax, dword [p.v_value]
!mov ecx, dword [p.v_count]
!shl eax, cl
ProcedureReturn
EndProcedure
; Bitshift right shift
Procedure SHR32(value.l, count.l = 1)
!mov eax, dword [p.v_value]
!mov ecx, dword [p.v_count]
!shr eax, cl
ProcedureReturn
EndProcedure
Procedure BSWAP32(value.l)
!mov eax, dword [p.v_value]
!bswap eax
ProcedureReturn
EndProcedure
Procedure.w BSWAP16(value.w)
!xor eax,eax
!mov ax, word [p.v_value]
!rol ax, 8
ProcedureReturn
EndProcedure
;-Test
x = $80
x = shr8(x,2)
Debug RSet(Bin(x),8,"0")
x = $02
x = shl8(x,2)
Debug RSet(Bin(x),8,"0")
x = $01020304
x = bswap32(x)
Debug RSet(Hex(x),8,"0")
x = $0102
x = bswap16(x)
Debug RSet(Hex(x),8,"0")
x = %1001
x = shl32(x, 4)
Debug Bin(x)
x = %1001
x = shr32(x, 4)
Debug Bin(x)
x = %1001
x = rol32(x, 29)
Debug Bin(x)
x = %1001
x = ror32(x, 5)
Debug Bin(x)
Solange Du Dein Programm nicht mit Unicode Flag kompilierst kein Problem aber nach ein paarsix1 hat geschrieben:Ich habe den Typ durch.c ersetzt... eigentlich auch nicht ganz fein
Da liegt der Haken woanders!six1 hat geschrieben:der entscheidende Test ist:
b.b = 1 << 7
Debug RSet(Bin(b),8,"0")
Die Ausgabe lautet: %11111111
während der inline Debuger einfach -128 zeigt!
Code: Alles auswählen
a.b = 1
a << 7
Debug a
Debug Bin(a)
Debug RSet(Bin(a),8,"0")
Debug Bin(a & $FF)
b.b = 1 << 7
Debug b
Debug Bin(b)
Debug RSet(Bin(b),8,"0")
Debug Bin(b & $FF)
Code: Alles auswählen
-128
1111111111111111111111111111111111111111111111111111111110000000
11111111
10000000
-128
1111111111111111111111111111111111111111111111111111111110000000
11111111
10000000
RSet nimmt nun einfach die ersten 8 Bits und zeigt diese an
Code: Alles auswählen
b.b = 1 << 7
Debug Bin( b, #PB_Byte )
Weil beide Zahlen dem Wert -128 entsprechen:six1 hat geschrieben:was ich aber noch nicht verstehe ist, warum belegt "bin()" bei der Wandlung alles mit "1" vor?
Muss das so?
Code: Alles auswählen
b.b = %10000000
q.q = %1111111111111111111111111111111111111111111111111111111110000000
Debug b
Debug q
Code: Alles auswählen
-128
-128