ord() function

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 562
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

ord() function

Message par compsystems » sam. avr. 13, 2019 7:26 pm

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 > "₃"
... ₄₅₆₇₈₉

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: ord() function

Message par parisse » dim. avr. 14, 2019 5:53 am

Yes, it's UTF8 encoding.

compsystems
Messages : 562
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: ord() function

Message par compsystems » mer. avr. 17, 2019 8:02 pm

ord("₀") returns -30 and not 8320

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: ord() function

Message par parisse » jeu. avr. 18, 2019 6:41 pm

Xcas parser uses UTF8 encoding, you will never get 16 bits integer. There are additional restrictions in ord, UTF8 is indeed not supported.

Répondre