如何在不使用任何内置函数的情况下将STRING转换为INT. [英] HOW TO CONVERT STRING to INT without using any inbuilt functions..??
问题描述
大家好,
如何将我的String str = 10转换为int s = 10;而不使用任何内置库,例如解析或转换为int等.我在面试中遇到了这个问题...但是我尝试了一些二进制级别的尝试,但是没有被接受.pls阐明了内部数据转换是如何发生的...
How to Convert my String str=10 into int s=10; without using any inbuilt libraries like parse or convert to int etc. I had this question in interview...but i tried something in binary level but not accepted.pls clarify how internally data conversion takes place...
谢谢.
Maheshkumar.R
Maheshkumar.R
推荐答案
好吧,我从未有过像这样的采访,但我想他们希望看到您手动进行;)
well, i never had an interview like this, but I guess they want to see you doing it manually ;)
有点像这样:
string sx ="10";
int ix = 0;
for(int i = 0; i
ix * = 10;
ix + = sx [i] -48;
}
string sx = "10";
int ix = 0;
for (int i=0; i<sx.Length; i++)
{
ix *= 10;
ix += sx[ i ]-48;
}
这篇关于如何在不使用任何内置函数的情况下将STRING转换为INT.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!