Android Question Char = Int?

wonder

Expert
Licensed User
Longtime User
Why isn't it possible to perform arithmetic with chars and ints, without having to use the asc() function?
B4X:
'Not legal
Dim d = "d" As Char
Dim a = d - 3 As Int

'Legal
Dim d = "d" As Char
Dim a = asc(d) - 3 As Int

Isn't char a primitive type?
 

DonManfred

Expert
Licensed User
Longtime User
The problem seems that "d" (the Char object) cannot be cast to a number...

Char "d" will result in "d", not in a number... To get the int you need to use asc("d")

isn't Char just an Int "disguised" as an ASCII character?

the value of char does not fit into 0-255 like you expect i guess. char can hold a value of 0 to 65535
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
char can hold a value of 0 to 65535
So the B4A char is nothing like the C-family char... right?

(Sorry for nagging about this, I'm timing some code to the nanosecond...)
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I remember back I the early z80 qbasic, I used to create menu borders by using the Char$ keyword to access "symbols" not directly available with the keyboard

At that time we didn't have that much fonts, so it was like looking up a fixed table, now, with all the existing fonts, char(250) can be a letter or a symbol depending on the font in use
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
no, under android this is a B4A thread ;)

more weirdness...

I copied the sub and named it getInt2

when I call that it's a lot faster than the original sub, even when swapping the calls. wth!
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
in release mode is always seems to win compared to parseInt, logical as that supports more than 10 base alone.

it's still creepy that the differences between calling the same routine can be so huge.
(I'm talking here abte the time of 10.000 runs of the same sub call)
 
Upvote 0
Top