Restored from previous forum. Originally posted by CodeMeister.
Are there any binary bit-shifting functions in PB such as shift left or shift right? I didn't see any mention in the docs. Thx.
"If stupidity got us into this mess, why can't it get us out?"
Bit Shifting functions
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by BalrogSoft.
Right shift:
Bit2.s=Bin(Val(Right(Value.s,1)))
Bitshifted=Val(Right(Bit2.s,1)) ; save the bit losed
Val(Value.s)/2 ; and this the real bit shift to right, only divide the value by 2
Left shift:
Bit1.s=Bin(Val(Left(Value.s,1)))
Bitshifted=Val(Left(Bit1.s,1)) ; save the bit losed
Val(Value.s)*2 ; and make the left shift
if you only need the shift data and not the losed data, only multiply or divide the value by 2 to make the shift operation.
bye, Balrog Soft
Balrog Soft
Amiga and PC Coder
http://www.balrogsoftware.com
[url]mailto:balrog@balrogsoftware.com[/url]
There isnt any function to do this, but in my chip 8 emulator, exist two emulated instructions that are right shift and left shift, and in a document i discover how to make it very fast:Originally posted by CodeMeister
Are there any binary bit-shifting functions in PB such as shift left or shift right? I didn't see any mention in the docs. Thx.
"If stupidity got us into this mess, why can't it get us out?"
Right shift:
Bit2.s=Bin(Val(Right(Value.s,1)))
Bitshifted=Val(Right(Bit2.s,1)) ; save the bit losed
Val(Value.s)/2 ; and this the real bit shift to right, only divide the value by 2
Left shift:
Bit1.s=Bin(Val(Left(Value.s,1)))
Bitshifted=Val(Left(Bit1.s,1)) ; save the bit losed
Val(Value.s)*2 ; and make the left shift
if you only need the shift data and not the losed data, only multiply or divide the value by 2 to make the shift operation.
bye, Balrog Soft
Balrog Soft
Amiga and PC Coder
http://www.balrogsoftware.com
[url]mailto:balrog@balrogsoftware.com[/url]
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Skipsy.
Hi,
Perhaps I didn't understood your need but for a 1 bit left shift you
can multiply by 2 and for a right shift divide by 2
Then of course you can format the binary data to 4, 8 or more bits,
with a AND (&).
"If you want to touch the sky,
f**k a duck and try to fly"
Hi,
Perhaps I didn't understood your need but for a 1 bit left shift you
can multiply by 2 and for a right shift divide by 2
Then of course you can format the binary data to 4, 8 or more bits,
with a AND (&).
"If you want to touch the sky,
f**k a duck and try to fly"
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm