当前位置:网站首页>Convert the string to hexadecimal string and display it
Convert the string to hexadecimal string and display it
2022-06-12 13:40:00 【Li. CQ】
Convert the string to 16 Hexadecimal string and display
Barrage agreement I
// - Bytes sent
5d0000005d000000b1020000xxxxxxx00
5d000000 : Send content length ( The length of the content = (5d000000 The length of the content 4 byte ) + (b1020000 Version information length 4 byte ) (xxxxxxx) The length of + (00 Message tail 1 byte ) )
5d000000 : Length of content sent ( The length of the content = (5d000000 The length of the content 4 byte ) + (b1020000 Version information length 4 byte ) (xxxxxxx) The length of + (00 Message tail 1 byte ) )
b1020000 : Version information characters (b1020000 4 byte )
xxxxxxx : Sent content ;
00 : Fixed characters at the end
// - String rotation data
NSData *data = [self.msgContent dataUsingEncoding:NSUTF8StringEncoding];
NSMutableString *content = [NSMutableString string];
// - Fixed characters inside
char tail = 0x00;
int version = 0x000002b1;
int length = (int)(sizeof(length) + sizeof(version) + data.length + sizeof(tail));
// - Byte order conversion
tail = CFSwapInt32(tail);
version = CFSwapInt32(version);
length = CFSwapInt32(length);
// - Concatenate numbers into strings ( With 16 The form of base , %08x If the number is 0x08, Just change it to 0x00000008)
NSString *header = [NSString stringWithFormat:@"%08x%08x%08x", length, length, version];
// - take bytes Each character in is spliced into a string ( With 16 The form of base , %08x If the number is 0x08, Just change it to 0x00000008)
// - The use here is unsigned char without char There is a reason for example , " I " The code of is E6 88 91, Use char Will turn into FFFFFFE6 FFFFFF88 FFFFFF91, While using unsigned char Will turn into E68891 [ Data address ](https://www.geek-share.com/detail/2764755658.html)
for (int i = 0; i < data.length; i++) {
unsigned char va = *(char *)(data.bytes + i);
[content appendFormat:@"%02x", va];
}
// - Stitching result string
NSString *result = [NSString stringWithFormat:@"%@%@%02x", header, content, tail];
return result;
Barrage agreement II
NSDictionary *contentDic = [self.msgContent toDictionary];
if (!contentDic) return nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:contentDic options:NSJSONWritingPrettyPrinted error:nil];
NSMutableString *content = [NSMutableString string];
int headerLenth = 16;
int contentLen = CFSwapInt32LittleToHost((int)(data.length + headerLenth));
short headerLen = CFSwapInt16LittleToHost(headerLenth);
short version = CFSwapInt16LittleToHost(1);
int operation = CFSwapInt32LittleToHost(self.operationCode);
int seq = CFSwapInt32LittleToHost(0);
NSString *header = [NSString stringWithFormat:@"%08x%04x%04x%08x%08x", contentLen, headerLen, version, operation, seq];
for (int i = 0; i < data.length; i++) {
unsigned char va = *(char *)(data.bytes + i);
[content appendFormat:@"%02x", va];
}
NSString *result = [NSString stringWithFormat:@"%@%@", header, content];
return result;
边栏推荐
- import torch_ Geometric loads some common datasets
- RK3399平台开发系列讲解(内核调试篇)2.50、systrace的使用
- torch_ About the geometric Mini batch
- 安装MySQL时出错,照着下面这个链接,做到cmd就不行了
- Application of binary search -- finding the square root sqrt of a number
- Dameng database DM8 Windows environment installation
- Successfully rated Tencent t3-2, 10000 word parsing
- Cocoapods的相关知识点
- Install RPM package offline using yum
- Tensorrt, onnx to tensorrt in mmclas
猜你喜欢

Pytorch framework

镜像扫描工具预研

关于#SQLite写注册功能时,数据表查询出错#的问题,如何解决?

import torch_geometric 的Data 查看
![[Title brushing] Super washing machine](/img/f9/0c69afafa8b32afc5df5e91d6af172.png)
[Title brushing] Super washing machine

Paw 高级使用指南

安装MySQL时出错,照着下面这个链接,做到cmd就不行了

It is enough to read this article. Web Chinese development
颜色编码格式介绍
![Will the next star of PPT for workplace speech be you [perfect summary] at the moment](/img/11/ac67db2641f42ef3d09417b790feb8.png)
Will the next star of PPT for workplace speech be you [perfect summary] at the moment
随机推荐
【SemiDrive源码分析】【X9芯片启动流程】26 - R5 SafetyOS 之 LK_INIT_LEVEL_TARGET 阶段代码流程分析(TP Drvier、Audio Server初始化)
Seekg, tellg related file operations
看完这一篇就够了,web中文开发
Application of bit operation in C language
D1 哪吒开发板 了解基本的启动加载流程
Wechat web developer tools tutorial, web development issues
Successful job hopping Ali, advanced learning
FFmpeg 学习指南
import torch_ Geometric first graph network example
Octopus network progress monthly report | may 1-May 31, 2022
Resume NFT platform trustrecruit joined Octopus network as a candidate application chain
Install RPM package offline using yum
Stm32f1 and stm32subeide programming example - device driver -dht11 temperature sensor driver
2061: [example 1.2] trapezoidal area
播放器屏幕方向方案
章鱼网络进展月报 | 2022.5.1-5.31
Teach you how to create SSM project structure in idea
m1 pod install pod lint 失败解决方案
IC chip scheme fs4062b for lithium battery charging with 5V boost to 12.6V
Time processing in C language (conversion between string and timestamp)