小鹏笔记 第三期(持续更新)

学习Tips

  • ios中将16进制转换为浮点型
NSString *temp = [NSString stringWithFormat:@"%@%@",@"0x",[[[temp0 stringByAppendingString:temp1] stringByAppendingString:temp2] stringByAppendingString:temp3]];
            
const char *str = NULL;
 if ([temp canBeConvertedToEncoding:NSUTF8StringEncoding]) {
      str = [temp cStringUsingEncoding:NSUTF8StringEncoding];
}
uint32_t num;
float f;
sscanf(str, "%x", &num);  // assuming you checked input
f = *((float*)&num);
printf("the hexadecimal 0x%08x becomes %.3f as a float\n", num, f);
  • CRC16-MODBUS校验(OC版本代码)
+ (NSString *)getCrc16_MODBUSWithString:(NSString *)str{
    
    NSArray *array = [[NSArray alloc]initWithArray:[self seperateStr:str byLength:2]];
    unsigned short tmp = 0xffff;
    unsigned short ret1 = 0;
    Byte buff[10240] = {};
    
    for (int i = 0; i < array.count; i++) {
        buff[i] = [[self decimalStringFromHexString:array[i]] intValue];//  这个是10进制转换成16进制
    }
  
    for(int n = 0; n < array.count; n++){
        tmp = buff[n] ^ tmp;
        for(int i = 0;i < 8;i++){  /*此处的8 -- 指每一个char类型又8bit,每bit都要处理*/
            if(tmp & 0x01){
                tmp = tmp >> 1;
                tmp = tmp ^ 0xa001;
            }
            else{
                tmp = tmp >> 1;
            }
        }
    }
    /*CRC校验后的值*/
    printf("校验后的值%X\n",tmp);
    /*将CRC校验的高低位对换位置*/
    ret1 = tmp >> 8;
    ret1 = ret1 | (tmp << 8);
    printf("高低位对换后的值ret: %X\n",ret1);
    
    NSString *returnStr = [NSString stringWithFormat:@"%X",ret1];
    return returnStr;
}

工具推荐

  • 在线PS工具

地址 https://www.gaituya.com/

  • Wallhaven壁纸

地址 https://wallhaven.cc/

  • 免费字体(fontspace)

地址 https://www.fontspace.com/

  • 免费流程图绘制软件

地址 https://www.iodraw.com/

  • 综合网址

地址 https://www.cxy521.com

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容