[英]How to find a position in a integer
If I had a integer that was, for example 11110011. How would I find out what number was in each position so I could use them calculate something. 如果我有一个整数,例如11110011。我将如何找出每个位置的数字,以便可以使用它们计算出一些东西。 Thanks
谢谢
将其强制转换为String,然后使用string方法在特定位置查找int。
Feel free to read a bit about operators if you wish. 如果您愿意,可以随时阅读一些有关运算符的信息。 Anyhow i'd use a loop of
Mod 10
and divide by 10 each iteration. 无论如何,我会使用
Mod 10
的循环并在每次迭代中除以10。
Pseudo code: 伪代码:
Given number
While number is not zero
Get the mod 10 of the number
... Do what you need to do with it - that's the digit
Divide by 10.
Repeat.
Done.
for example: 例如:
Dim yourNumber As Integer = 12930 // for example.
While index >0
Dim digit As Integer = yourNumber Mod 10
Debug.Write(digit.ToString & " ")
index /= 1
End While
Will write all the digits, seperated by a space: 将写所有数字,并用空格分隔:
output: 1 2 3 9 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.