Bit Shifting functions

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

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?"
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wayne1.

Look under General Topics
variables types and operators
in the reference manual :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by CodeMeister.

Thx wayne1... right where you said it would be.... 8^)

"If stupidity got us into this mess, why can't it get us out?"
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by BalrogSoft.
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?"
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:

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
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Have you tried: > ?

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

Post by BackupUser »

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"
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by CodeMeister.

Thx guys... I found the > operators, just what I needed.


"In God we trust, all others we virus scan." ~Author Unknown
Post Reply