Summation of a character
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Edward Huang
le 20 Juin 2019
Modifié(e) : Stephen23
le 20 Juin 2019
I was working on Cody Problem 74 where I found examples like:
sum('13') = 100
sum('22') = 100
sum('123456') = 309
I wonder how it works here, i.e., sums a character but returns a double.
Thanks in advance.
0 commentaires
Réponse acceptée
Plus de réponses (1)
KSSV
le 20 Juin 2019
Read about uint16. This will convert the characters into numeric codes. When you use sum on the characters, they will be converted to uint16 numbers and gets summed up. Check below code.
a = uint16('13') ;
b = uint16('22') ;
c = uint16('123456') ;
In the above sum(a) and sum('13') are same.
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!