如何在 Objective-C 中从 CFReadStream 中仅提取前 2 个字节的数据以进行 iPhone 编程
如何从 Objective-C 的读取流中读取数据?下面的代码将告诉我从流中读取了多少字节,但是我如何知道从流中读取了哪些数据?
CFIndex cf = CFReadStreameRead(流、缓冲区、长度);
如何在 Objective-C 中仅提取读取流中的前 2 个字节数据?例如,如果这是来自流的数据:
<前><代码>017MacApp第一个字节有 0,第二个字节有 17。
如何将 0 和 17 提取到字节数组中?
我知道下面的代码会将字节数组返回给 int 值。
((b[0] & 0xFF) << 8)+ (b[1] & 0xFF);
但是如何将 0 放入 b[0] 并将 17 放入 b[1] 呢?
How can I read the data from read stream in Objective-C? The code below would give me how many bytes are read from stream, but how can I know what data is read from stream?
CFIndex cf = CFReadStreameRead(Stream, buffer, length);
How can I extract only the 1st 2bytes of data in the read stream in Objective-C? For example, if this is the data from stream:
017MacApp
1st byte has 0 in it, and 2nd byte has 17 in it.
How do I extract 0 and 17 into byte array?
I know that the below code would give me back the byte array to int value.
((b[0] & 0xFF) << 8)+ (b[1] & 0xFF);
but how to put 0 into b[0] and 17 into b[1]?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 苹果文档。
Here is the Apple doc.