iOS:将整数数据转换为字节格式

时间:2015-02-17 06:46:40

标签: ios objective-c int bytearray

我需要将给定的整数转换为字节格式.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*/

如果有任何可用的示例代码,请帮助如何将上述整数值转换为字节格式。

1 个答案:

答案 0 :(得分:-1)

你可以试试这个,

[NSData dataWithBytes:&myInteger length:sizeof(myInteger)];
祝你好运。