Page 1 sur 1

ord() function

Publié : sam. avr. 13, 2019 7:26 pm
par compsystems
Hello, I am coding a prg that converts a number between 0 and 9 to a subscript character, but it seems that the ORD command only operates between 0 and 255 =(

Code : Tout sélectionner

def toSubscript(n):
    local subscriptStr
    DispG
    if ord(string(n))>=48 and ord(string(n))<=57:
       subscriptStr :=  char(n+8272) # char(n+48)
       return subscriptStr, ord(subscriptStr), asc(subscriptStr)
    else: 
        return "error"
char(8320) >"₀"
ord("₀") > 8320

toSubscript(n)
n
0 > "₀"
1 > "₁"
2 > "₂"
3 > "₃"
... ₄₅₆₇₈₉

Re: ord() function

Publié : dim. avr. 14, 2019 5:53 am
par parisse
Yes, it's UTF8 encoding.

Re: ord() function

Publié : mer. avr. 17, 2019 8:02 pm
par compsystems
ord("₀") returns -30 and not 8320

Re: ord() function

Publié : jeu. avr. 18, 2019 6:41 pm
par parisse
Xcas parser uses UTF8 encoding, you will never get 16 bits integer. There are additional restrictions in ord, UTF8 is indeed not supported.