Wish Bitwise operations, easier/quicker way of doing them?

Roger Taylor

Member
Licensed User
Longtime User
I remember bringing this up some time back and I'm sure others have asked about it, but....
Having to do something like this:
var = bit.or(var, 32) in my opinion is a bit extreme and possibly much slower?

I know B4A isn't an assembler, but even the oldest BASIC around uses OR/AND/NOT.
A = 128 OR 32

Bit shifting is sometimes done by << and >> in some languages instead of having to use a library function or subroutine. But I know B4A isn't designed to be closer to an assembler than a high-level compiler.

I'm working on a emulator that has a 6809 CPU and although it runs fast on a lot of Android devices, even the fastest Fire Stick is choking on all the extreme ways I have to do bit logic. It's in my interest to pester the living daylights out of the author to please give this some more thought. :)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
and possibly much slower?
FWIW, it is not slower. I did test it in the past. The Java compiler is very sophisticated and handles it optimally. In B4i and B4R these methods (as well as many others) are inlined.
You can see it in the library XML:
B4X:
<name DesignerName="Xor">Xor::</name>
<comment>Returns the bitwise XOR of the two values.</comment>
<returntype>int</returntype>
<parameter>
    <name>N1</name>
    <type>int</type>
</parameter>
<parameter>
    <name>N2</name>
    <type>int</type>
</parameter>
<inlines>
    <inline>((</inline>
    <inline>) ^ (</inline>
    <inline>))</inline>
</inlines>

I found out that it is not needed in B4A / B4J.
 
Top