ich habe gerade festgestellt, dass PureBasic nur arithmetisches Shiften erlaubt, heißt:
Code: Alles auswählen
a.b = %11111001
a >> 2
Debug RSet(Bin(a,#PB_Byte),8,"0")
; %11111110
; statt %00111110
lg Kevin
Code: Alles auswählen
a.b = %11111001
a >> 2
Debug RSet(Bin(a,#PB_Byte),8,"0")
; %11111110
; statt %00111110
padawan hat geschrieben:Ich liebe diese von hinten über die Brust ins Auge Lösungen
Code: Alles auswählen
a>>2
a!%11000000
Code: Alles auswählen
a.a = %11111001
a >> 2
Debug RSet(Bin(a,#PB_Byte),8,"0")
; %11111110
; statt %00111110
Warum eigentlich nicht Integer?
Und nein, ich meine kein signed - unsign durch &.Vorweg ich benutze den Typ Integer (komma?) nicht Byte und will alle 32 bzw. 64 Bits benutzen.
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 : 18.07.2016
;
; Compilermode :
;
; ***************************************************************************************
; Bitshift left rotation
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 right 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 rotation
Procedure ROL64(value.q, count.q = 1)
!mov rax, qword [p.v_value]
!mov rcx, qword [p.v_count]
!rol rax, cl
ProcedureReturn
EndProcedure
; Bitshift right rotation
Procedure ROR64(value.q, count.q = 1)
!mov rax, qword [p.v_value]
!mov rcx, qword [p.v_count]
!ror rax, 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
; Bitshift left shift
Procedure SHL64(value.q, count.q = 1)
!mov rax, qword [p.v_value]
!mov rcx, qword [p.v_count]
!shl rax, cl
ProcedureReturn
EndProcedure
; Bitshift right shift
Procedure SHR64(value.q, count.q = 1)
!mov rax, qword [p.v_value]
!mov rcx, qword [p.v_count]
!shr rax, cl
ProcedureReturn
EndProcedure
Procedure.w BSWAP16(value.w)
!xor eax,eax
!mov ax, word [p.v_value]
!rol ax, 8
ProcedureReturn
EndProcedure
Procedure BSWAP32(value.l)
!mov eax, dword [p.v_value]
!bswap eax
ProcedureReturn
EndProcedure
Procedure BSWAP64(value.q)
!mov rax, qword [p.v_value]
!bswap rax
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)
x = %1001
x = shl64(x, 4)
Debug Bin(x)
x = %1001
x = shr64(x, 4)
Debug Bin(x)
x = %1001
x = rol64(x, 29)
Debug Bin(x)
x = %1001
x = ror64(x, 5)
Debug Bin(x)
Code: Alles auswählen
; statt
value = SHR32(#MeineMaske, shift)
; das
value = MeineMaske(shift)
padawan hat geschrieben:Ich liebe diese von hinten über die Brust ins Auge Lösungen