What is the difference between 5 and '5'
6 次查看(过去 30 天)
显示 更早的评论
5 + 1 = 6
'5' + 1 = 54
Why does the seceond line equal 54???
What does '' around numbers???
采纳的回答
Bruno Luong
2019-8-27
编辑:Bruno Luong
2019-8-27
The '5' is the char array. Char array contain a text including number, such as 'Schrodinger has 2 dogs and 1/2 cat'. Char array uses ASCII code internally (actually UNICODE) and the ascii code of '5' is 53, therefore '5'+1 = 53+1 = 54
5 (without quote) is number 5, where the arithmetics operations has standard meaning.
2 个评论
Walter Roberson
2019-8-28
There are deep historical reasons why the digits are not the first 10 positions in the character codes. It goes back to Morse code and the fact that Morse originally had no digits, and it goes back to mechanical selector lines...
For a while it looked like BCD or later EBCDIC would become the standard. EBCDIC coded '0' as the character after '9'.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!