int转byte
2015-09-21 22:16
330 查看
- (NSData *)little_intToByteWithData:(int)i andLength:(int)len{
Byte abyte[len];
if (len == 1) {
abyte[0] = (Byte) (0xff & i);
}
else if (len ==
2) {
abyte[0] = (Byte) (0xff & i);
abyte[1] = (Byte) ((0xff00 & i) >>
8);
}
else {
abyte[0] = (Byte) (0xff & i);
abyte[1] = (Byte) ((0xff00 & i) >>
8);
abyte[2] = (Byte) ((0xff0000 & i) >>
16);
abyte[3] = (Byte) ((0xff000000 & i) >>
24);
}
NSData *adata = [NSData
dataWithBytes:abyte
length:len];
return adata;
}
//测试int转byte--int占8位4个字节
int testInt = 25549;
NSData *da = [self
little_intToByteWithData:testInt andLength:32];
NSLog(@"da--->%@",da);
Byte abyte[len];
if (len == 1) {
abyte[0] = (Byte) (0xff & i);
}
else if (len ==
2) {
abyte[0] = (Byte) (0xff & i);
abyte[1] = (Byte) ((0xff00 & i) >>
8);
}
else {
abyte[0] = (Byte) (0xff & i);
abyte[1] = (Byte) ((0xff00 & i) >>
8);
abyte[2] = (Byte) ((0xff0000 & i) >>
16);
abyte[3] = (Byte) ((0xff000000 & i) >>
24);
}
NSData *adata = [NSData
dataWithBytes:abyte
length:len];
return adata;
}
//测试int转byte--int占8位4个字节
int testInt = 25549;
NSData *da = [self
little_intToByteWithData:testInt andLength:32];
NSLog(@"da--->%@",da);
相关文章推荐
- CF 一个不知道题号的题。。 B. ShortestPath Query
- UVa 12468 - Zapping
- 获取文件名后缀的方法
- 选用 get 与 post 的一些建议
- 0920编译原理词法分析-22陈施恩
- 单行bash、shell、perl命令
- 2015第39周一
- (算法)变成1需要的最小步数
- 黑马程序员——IOS学习笔记(内存释放的原则)
- 项目23.6 前导0的数字
- IC卡、ID卡及车库蓝牙卡的复制说明!(小区的门禁系统)
- IOS开发之深拷贝与浅拷贝(mutableCopy与Copy)详解
- Spark修炼之道(进阶篇)——Spark入门到精通:第六节 Spark编程模型(三)
- Linux:Vim
- URL解析
- 【软考之路】 软考视频总结(下)
- vim编辑器
- java编程基础2
- Android学习——Intent
- android 关联源码