operator 2^n ?? in B4a

alan1968

Active Member
Licensed User
Longtime User
used to being in vb using this type of formula to extract a bit, bit (n) = (xx and 2 ^ n) / 2 ^ n ,BA4 like doing the same thing?
thx!
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
It is a technical limitation. Java doesn't have an infix notation for power function.

That's pretty stupid.

You use VB or C# .NET?
If it's VB, and I made you a function to go into an equation and fix that, would you use it?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
That's pretty stupid.
It's not stupid, it's a design choice that was made for the Java language.
You use VB or C# .NET?
Of course he does, as do I. The Basic4android IDE is written (mainly) in C#. As it happens, like Java, C, C++ and C# all lack the exponentiation operator and implement it as a function. In those languages "^" is used as a logical bitwise XOR operator.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Using a known operator for something it's not intended for/not using it for what it is intended for is stupid, design choice or not. ^ is already used for exponents in math/other calculators/languages.

That just makes me hate the guy who made C even more.

The Basic4android IDE is written (mainly) in C#

So that's a no then. Dang.
 
Upvote 0

Mikie

Member
Licensed User
Longtime User
NeoTechni,

I just finished 20 years of teaching mathematics at a university in the US. You are being ridiculus. Learn to adapt.

Mikie
 
Upvote 0

BeneBarros

Active Member
Licensed User
Longtime User
GetBit and SetBit

this may help?

Sub GetBit(Bits As Int, BitNo As Int ) As Boolean
Return Bit.And(Bits,Power(2,(BitNo - 1)))/Power(2, (BitNo - 1))=1
End Sub

Sub SetBit(Bits As Int, BitNo As Int, Bstat As Boolean ) As Int
If Not(Bstat) Then
Bits = Bit.And(Bits,Bit.Not(Power(2, (BitNo - 1))))
Else
Bits = Bit.Or(Bits,Power(2, (BitNo - 1)))
End If
Return Bits
End Sub
 
Upvote 0

BeneBarros

Active Member
Licensed User
Longtime User
Sub GetBit(Bits As Int , BitNo As Int ) As Boolean
Return Bit.And(Bits,Power(2,(BitNo - 1)))/Power(2, (BitNo - 1))=1
End Sub
Sub SetBit(Bits As Int,BitNo As Int, Bstat As Boolean ) As Int
If Not(Bstat) Then
Bits=Bit.And(Bits,Bit.Not(Power(2, (BitNo - 1))))
Else
Bits = Bit.Or(Bits,Power(2, (BitNo - 1)))
End If
Return Bits
End Sub
 
Upvote 0

ukimiku

Active Member
Licensed User
Longtime User
I think we should (and are able to) keep the tone in our discussion friendly or neutral, so as not to hurt anyone who may have contributed questions or remarks that we could do without.

I suppose not all of us have a background of solid 20 years of teaching at a university, and even if we did have such a background, we would, I presume, probably have learnt so much about dealing with students (and students we all are here when we ask each other in order to learn and improve) and younger fellow attendants of our respective school that we could tolerate remarks uttered out of some sort of frustration with a benevolent and gracious attitude.

Thank you.

Regards,
 
Upvote 0
Top