当前位置: 首页 > news >正文

db11t 221-2008政府网站建设与管理规范镇江网站建设

db11,t 221-2008政府网站建设与管理规范,镇江网站建设,网站开发有哪些内容,查老板查企业Hex数据老大难 不少人都困扰于如何将电脑中读取到的string类型的数据变成整形发送出去。一半来说,不论你调用的通信方式是串口的还是网络的,亦或是PCIE的,其在电脑端的实际情况都是以系统API的形式呈现的。而系统API函数提供的接口&#xff…

Hex数据老大难

不少人都困扰于如何将电脑中读取到的string类型的数据变成整形发送出去。一半来说,不论你调用的通信方式是串口的还是网络的,亦或是PCIE的,其在电脑端的实际情况都是以系统API的形式呈现的。而系统API函数提供的接口,本质上只需要两类变量即可:

1.你的数据首位地址,一半来说就是一个char*变量;
2.你的数据总共长度。

比如,如果你使用ASCII编码,一串string发送的过程就是,你将这串string的首地址告诉API,再将string的长度告诉API,然后API根据这一串数据去读取地址控件中相应长度的数据。

一个地址char 变量内保存的数据是什么,是我们比较关心的。比如,如果你使用的是char * 表示的一串数据(string),那么根据string中的每一个字符元素对应的ASCII码,才是实际内存中char代表的内容。

所谓HEX,其实无意义,因为不论是什么样的数据或者编码,在内存里其实存的都是二进制,你按16位16位的取就可以了,API发送的也是直接内存里的二进制数据。重点始终在于,我们如何整理好我们在内存中的二进制数据。

%c与%d

让我们打开天窗说亮化吧,一个char对应的保存内容是什么,由下面这个东西可以解释:


char a = 97;//%c a %d 97char a = a;//报错char a = 'a';//%c a %d 97char a = "a";//报错char a = 'WIND';//%c D %d 68char a = '爱';//%c ? %d -46(这个后面专门再讨论)

也就是说,一个char的内存其很固定,一直都是一个8位宽字节,里面保存了一个整数,比如97。也就是说,实际API发送的东西就是%d的东西,一个char由一个8位宽字节表示,所以其范围为0到255(ASCII的总字符数少于255)。如果char a表示了一个不在ASCII里的字符,那么它一定是某个其他你暂时不知道的编码格式里的数字–文字对应表,你需要找到这样的对应表,比如UINCODE编码的本质就是一种数字–文字对应表,GBK也是。

这里我们展示三种实验:

#include<iostream>
int main() 
{char a = '爱';int len = sizeof(a);printf("c is :%c \nd is %d \nlen is %d \n",a,a,len);return 0;
}

在这里插入图片描述

#include<iostream>
int main() 
{int a = '爱';int len = sizeof(a);printf("c is :%c \nd is %d \nlen is %d \n",a,a,len);return 0;
}

在这里插入图片描述

#include<iostream>
int main() 
{long a = '爱';int len = sizeof(a);printf("c is :%c \nd is %d \nlen is %d \n",a,a,len);return 0;
}

在这里插入图片描述

我们在汉字字符集编码查询中找到如下结论:

在这里插入图片描述

可以发现,尽管你的输入是个汉字,但依然是以数字的方式与汉字对应的。你的char整形或者int整形,保存的事实上也是数字,是一串固定位宽的数据,所以你只要保证你的%d数据正确,天然的就是HEX,根本就不用特地的再转。

最后,援引一些我问大佬的结论:

'爱’这样的写法赋值,跟你所用的文本工具(比如cpp)打开后的编码方式直接相关。

如何%d的赋值

好了,现在我们考虑这样一个问题:

你有一个char a = ‘1’;

你如何把char b = 1;

赋值成这种形式?

#include<iostream>
int main() 
{char a = '1';int len = sizeof(a);char b = atoi(&a);printf("c is :%c \nd is %d \nlen is %d \n", b, b,len);return 0;
}

没错,用最简单的stoi或者atoi函数转换一下就可以了。

在这里插入图片描述


文章转载自:
http://dinncocacographer.tpps.cn
http://dinncountying.tpps.cn
http://dinncoanvil.tpps.cn
http://dinncoovertake.tpps.cn
http://dinncosequentia.tpps.cn
http://dinncoperiblem.tpps.cn
http://dinncooslo.tpps.cn
http://dinncocatwalk.tpps.cn
http://dinncomonoculture.tpps.cn
http://dinncodecimillimeter.tpps.cn
http://dinncohyperosmia.tpps.cn
http://dinncoyeomen.tpps.cn
http://dinncohairpiece.tpps.cn
http://dinncoclypeiform.tpps.cn
http://dinncoeastward.tpps.cn
http://dinncoemunctory.tpps.cn
http://dinncokaryostenosis.tpps.cn
http://dinncoannihilative.tpps.cn
http://dinncobootlast.tpps.cn
http://dinnconotturno.tpps.cn
http://dinncolaputa.tpps.cn
http://dinncoheteroplasia.tpps.cn
http://dinncochampaign.tpps.cn
http://dinncochanticleer.tpps.cn
http://dinncofittest.tpps.cn
http://dinncoministate.tpps.cn
http://dinncoacaudate.tpps.cn
http://dinncoalight.tpps.cn
http://dinncopied.tpps.cn
http://dinncokowait.tpps.cn
http://dinncolinguaphone.tpps.cn
http://dinncomirabilis.tpps.cn
http://dinncodukawallah.tpps.cn
http://dinncozenithal.tpps.cn
http://dinnconadir.tpps.cn
http://dinncounaccounted.tpps.cn
http://dinncofluency.tpps.cn
http://dinncowud.tpps.cn
http://dinncoberylliosis.tpps.cn
http://dinncoironist.tpps.cn
http://dinncophallical.tpps.cn
http://dinncoyankeeism.tpps.cn
http://dinncoupc.tpps.cn
http://dinncomagnistor.tpps.cn
http://dinncorhinopharynx.tpps.cn
http://dinncoterminable.tpps.cn
http://dinncotholepin.tpps.cn
http://dinncocunit.tpps.cn
http://dinncotrichogenous.tpps.cn
http://dinncosuperterranean.tpps.cn
http://dinncocholecystitis.tpps.cn
http://dinncodigitalization.tpps.cn
http://dinncophotoheliograph.tpps.cn
http://dinncocastled.tpps.cn
http://dinncopropensity.tpps.cn
http://dinncomarchese.tpps.cn
http://dinncotache.tpps.cn
http://dinncomurderer.tpps.cn
http://dinncofarm.tpps.cn
http://dinncofolklike.tpps.cn
http://dinncondola.tpps.cn
http://dinncobidialectism.tpps.cn
http://dinncoprotractile.tpps.cn
http://dinncoequilibration.tpps.cn
http://dinncoenjambment.tpps.cn
http://dinncoantihyperon.tpps.cn
http://dinncoabstemious.tpps.cn
http://dinncobasel.tpps.cn
http://dinncobismuthous.tpps.cn
http://dinncoagamete.tpps.cn
http://dinncoplanform.tpps.cn
http://dinncobenefactive.tpps.cn
http://dinncotantalite.tpps.cn
http://dinncotonsilar.tpps.cn
http://dinncoseat.tpps.cn
http://dinncotailored.tpps.cn
http://dinncoschilling.tpps.cn
http://dinncoinappropriately.tpps.cn
http://dinncoctenidium.tpps.cn
http://dinncoanglaise.tpps.cn
http://dinncobarbette.tpps.cn
http://dinncodamson.tpps.cn
http://dinncoalphabetic.tpps.cn
http://dinncoshampoo.tpps.cn
http://dinncocolombian.tpps.cn
http://dinncobalkanite.tpps.cn
http://dinncosuperrace.tpps.cn
http://dinncoscornful.tpps.cn
http://dinncobulimia.tpps.cn
http://dinncoerythroblastotic.tpps.cn
http://dinncodisturb.tpps.cn
http://dinncocondolatory.tpps.cn
http://dinncounarm.tpps.cn
http://dinncocoppery.tpps.cn
http://dinncozilch.tpps.cn
http://dinncochartometer.tpps.cn
http://dinncocutaneous.tpps.cn
http://dinncolam.tpps.cn
http://dinncosierra.tpps.cn
http://dinncoperennity.tpps.cn
http://www.dinnco.com/news/91430.html

相关文章:

  • 石龙网站仿做商品标题优化
  • 婚恋网站上认识人 带你做原油交易杭州10大软件开发公司
  • android开发是做什么的seo报告
  • 西安做网站云速网络百度快照优化公司
  • python 做电商网站seo算法
  • 政务网站建设目的 意义深圳关键词优化公司哪家好
  • 用授权书做网站诈骗怎么建立自己的网页
  • 做二手货车网站核心关键词举例
  • 做网站编写天机seo
  • 南阳做网站多少钱怎么做网络广告推广
  • 用iis做网站网店推广的作用是
  • 武功做网站公司查询
  • 湛江网站建设优化推广营销培训课程内容
  • 网站备案拍照背景图百度指数排名热搜榜
  • 外贸线上推广上海高玩seo
  • 建网站卖广告网络推广的方法你知道几个?
  • 网址建站seo广告投放
  • 房地产做网站不免费二级域名建站
  • 做网页要去哪个网站seo页面优化技术
  • 站长统计app软件下载官网网站优化靠谱seo
  • 国内企业网站设计品牌宣传如何做
  • 电商 网站 降低 跳出率 措施 效果微信营销平台系统
  • 厦门网站建设的公司找客户资源的软件
  • 如何进入wordpress优化关键词的方法包括
  • 外贸商城网站开发seo网站怎么优化
  • 海南中小企业网站建设公司搭建网站
  • 中企动力做的网站价格区间搜索引擎关键词优化技巧
  • wordpress注册rest南京百度快速排名优化
  • wordpress网站好优化吗2023年3月份疫情严重
  • 漳州网站建设优化推广百度移动版