Alex Rivera | Logout

How compiler is converting integer to string and vice versa

Asked 2011-08-19T15:00:01.163
10

Many languages have functions for converting string to integer and vice versa. So what happens there? What algorithm is being executed during conversion?

I don't ask in specific language because I think it should be similar in all of them.

Edit
Report

1 Answer

1

I wouldn't call it an algorithm per se, but depending on the language it will involve the conversion of characters into their integral equivalent. Many languages will either stop on the first character that cannot be represented as an integer (e.g. the letter a), will blindly convert all characters into their ASCII value (e.g. the letter a becomes 97), or will ignore characters that cannot be represented as integers and only convert the ones that can - or return 0 / empty. You have to get more specific on the framework/language to provide more information.

answered 2011-08-19T15:08:44.427

Your Answer