【发布时间】:2012-09-25 13:27:42
【问题描述】:
我正在 Windows 和 iOS 上制作一个项目。
在 Windows 中,我从用户那里获取输入,将其转换为字节数组,通过向每个字节添加大的随机值来操作数组(有点像对其进行编码),然后将转换为字符串的字节数组返回给用户。
我想在 iOS 应用中实现相同的功能。 我从 UITextField 获取输入(出口说:myTextField)
现在的问题是,我如何将它转换为 Windows 中的字节数组并对其进行操作。 我搜索了堆栈溢出,发现了这段代码
const char *bytearray = [self.myTextField.text UTF8String];
使用它,它给了我一个我想要的字节数组,但它是一个 const char *,我无法操作它。 那么如何将其存储在数组中以进行操作。
另外,当在 windows 中向数组中的字节添加值时,如果值超过 256,它会自动保持在 256 以内(例如,115 + 300,它存储为 159),这简化了我减去值的过程和取回原来的值。如何在 iOS 应用中做到这一点。
For a better clarity, I'll give an example of how it works in Windows
byte array contains 'n' (Decimal value: 110)
adding 200 to it stores '6' (Decimal value: 54)
[310 % 256 = 54]
When retrieving back original value I subtract 200 from '6' (54 - 200 = -146)
and get the original value (256 - 146 = 110)
All this is done automatically, by using a byte array (this 256 - 146 thing)
如何在 iOS 中实现这种字节数组功能?
【问题讨论】:
标签: ios arrays nsstring byte type-conversion