PB doesn't like bitwise addition?

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 halo.

This produces an assembly error:

If Pow(2,n-31) And Int(tvalue)
SetGadgetState(n,1)
Else
SetGadgetState(n,0)
EndIf

If I have a value like 9, how do I use that to determine that the value for 1 and 3 are true? Usually I just say "if 2^3 and 9..."
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 Paul.

Look in the help file under "Variables & Types"
You will see that AND is logical, & is bitwise.

Code: Select all

num1=Pow(2,n-31)
num2=Int(tvalue)
 
If num1 & num2
 SetGadgetState(n,1)
 Else
 SetGadgetState(n,0)
EndIf


Edited by - paul on 15 July 2002 21:12:46
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 halo.

Isn't it odd that my code would produce an assembly error?
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 fweil.

I suppose the assembly error message comes from that you are using Pow function inside an integer logical formula.

It may looks strange to you but you are using a formula which is not using same kind of operands together.

Then the second point seems that when using logical functions, bitwise or not, uses registers so that you have to take care of calling variables inside formulas.

Just check any complex instruction you write to be sure.

It is possible that some of issues commented correspond to bugs or just to a misuse of PureBasic. I do not want to take a long time to check different cases I know. But it is always possible to react when getting an compiler error message by writing the same thing in another way.

As a tip for you, I suggest you use > operators instead of Pow function when building binary operands. It is also much faster.

Rgrds

Francois Weil
14, rue Douer
F64100 Bayonne
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 Danilo.

PureBasic\Compilers\Nasm.out:
PureBasic.asm:79: invalid combination of opcode and operands
PureBasic.asm:83: invalid combination of opcode and operands

Code: Select all

[b]79|  AND    1073741824,1073741824[/b]
80|  JE      NEAR _AO_No0
81|  FILD   dword [v_tvalue]
82|  FRNDINT
[b]83|  AND    ST0,ST0[/b]
generated ASM is wrong, so Fred should take a look.

cya,
...Danilo
(registered PureBasic user)

Edited by - Danilo on 16 July 2002 08:51:04
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 Danilo.

BTW: command Int() isnt in the PB-Help.

Cant find it under "MATH" and command+F1 shows error page...

cya,
...Danilo

(registered PureBasic user)
Post Reply