iOS -- 字符串(NSString *)转uint8_t的两种方法
2024-09-06 09:50:41
// 第一种
NSString *connID = ((Collector *)weakSelf.globalMutableArray[i]).orignalConnID;
const uint8_t a = [[connID substringToIndex:] intValue];
NSRange bRange = {, };
const uint8_t b = [[connID substringWithRange:bRange] intValue];
NSRange cRange = {, };
const uint8_t c = [[connID substringWithRange:cRange] intValue];
const uint8_t d = [[connID substringFromIndex:] intValue]; //第二种
NSString *str = @"AA21f0c1762a3abc299c013abe7dbcc50001DD";
NSData* bytes = [str dataUsingEncoding:NSUTF8StringEncoding];
Byte * myByte = (Byte *)[bytes bytes];
NSLog(@"myByte = %hhu",myByte[]);
NSMutableData* data = [NSMutableData data];
NSScanner* scanner = [NSScanner scannerWithString:@"AA"];
unsigned intValue;
[scanner scanHexInt:&intValue];
[data appendBytes:&intValue length:];
Byte * yte = (Byte *)[data bytes];
// 拿到的数据
const uint8_t senddata[] = {0xEB, 0x90, 0x00, 0x05, 0x06, a, b, c, d, 0x87};
觉得有用还是没用都评论哦! ^..^!!!
最新文章
- November 3rd Week 45th Thursday 2016
- 深入理解DOM事件类型系列第三篇——变动事件
- Find Minimum in Rotated Sorted Array leetcode java
- dom4j操作xml
- 题解西电OJ (Problem 1006 - 转盘游戏)--动态规划
- 浏览器检测(BrowserDetect.js)
- C++ STL (备忘)
- C#操作Office.word(一)
- BZOJ 1096
- TWinControl.DefaultHandler处理WM_CTLCOLORMSGBOX..WM_CTLCOLORSTATIC消息的两个参数很有意思,两个都是传递句柄
- Entity Framework Core 2.0 中使用LIKE 操作符
- python—文件处理
- [Swift]LeetCode295. 数据流的中位数 | Find Median from Data Stream
- vue-cli脚手架(框架)
- 数组练习题A财务管理
- Git远程仓库地址变更本地如何修改
- Unity应用架构设计(2)——使用中介者模式解耦ViewModel之间通信
- 使用policheck 检测
- React半科普文
- 基于jquery的ui选择之路
热门文章
- JVM执行子系统探究——类文件结构初窥
- 关于freetype在安装中的遇到的问题
- Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies
- python - 接口自动化测试 - contants - 常量封装
- python - 接口自动化测试实战 - case1 - 再次优化版
- python - 自动化测试框架 - logger
- ZOJ-3956 Course Selection System,01背包!
- PHPSTORM+Thinkphp3.2模板标签替换Thinkphp5.1公式
- 利用MVC模式简单设计jsp分页效果
- BZOJ 4584 [Apio2016]赛艇 ——动态规划