我需要将给定的整数转换为字节格式.i.e如下所示。是否有任何解决方案,因为我是iOS的新手,我找到了一些链接,但没有帮助。
int year=24;
Byte command[2]
command[0]=/* some thing that converted above*/
command[1]=/* some thing that converted above*/
command[2]=/* some thing that converted above*/
如果有任何可用的示例代码,请帮助如何将上述整数值转换为字节格式。
答案 0 :(得分:-1)
你可以试试这个,
[NSData dataWithBytes:&myInteger length:sizeof(myInteger)];
祝你好运。