long a=;
float b=34.56745f;
float c=0.0; byte fbs[]={,,,};
byte* t=fbs;
float2Bytes(t,b);
unsigned int addrF=(unsigned int) &b;
unsigned int addrFc=(unsigned int) &c; Serial.println(addrF);
Serial.println(addrFc);
float x= bytes2Float(fbs); for(int i=;i<;i++){
byte bf1=*((byte*)(addrF + i));
*((byte*)(addrFc + i))=bf1;
Serial.print(bf1,HEX);
if(i<) Serial.print("-");
}
Serial.println(" "); for(int j=;j<;j++){
Serial.print(fbs[j],HEX);
if(j<)Serial.print("-"); }
Serial.println(" ");
Serial.print("c:");
Serial.println(c,); Serial.print("x:");
Serial.println(x,); Serial.println(sizeof(b));
void float2Bytes(byte bytes_temp[],float float_variable){
union {
float a;
byte bytes[];
} thing;
thing.a = float_variable;
memcpy(bytes_temp, thing.bytes, );
} float bytes2Float(byte bytes_temp[]){
union {
float a;
byte bytes[];
} thing; memcpy(thing.bytes,bytes_temp, );
return thing.a;
} //查找字节数组中是否以指定的字符串开头
boolean bStartsWith(byte data[],int len, String fStr){
int fLen=fStr.length() ;
byte fBytes[fLen + ];
fStr.getBytes(fBytes,fLen+); if(len<=)return false;
if(len<fLen)return false;
byte flag=;
for(int j=;j<fLen;j++){
if(fBytes[j]!=data[j])
{
flag=;
break;
} }
if(flag) return true; return false;
} void long2byte(unsigned long res,byte targets[] ) {
targets[] = (byte) (res & 0xff);
targets[] = (byte) ((res >> ) & 0xff);
targets[] = (byte) ((res >> ) & 0xff);
targets[] = (byte) (res >> ); } unsigned long bytes2long(byte buf[]) {
unsigned long firstByte = ;
unsigned long secondByte = ;
unsigned long thirdByte = ;
unsigned long fourthByte = ;
int index = ;
firstByte = (0x000000FFU & ( buf[index+]));
secondByte = (0x000000FFU & ( buf[index + ]));
thirdByte = (0x000000FFU & ( buf[index + ]));
fourthByte = (0x000000FFU & ( buf[index ]));
index = index + ;
return ((unsigned long) (firstByte << | secondByte << | thirdByte << | fourthByte)) & 0xFFFFFFFFUL;
}

int array[13];

int * addrArr=array; //数组可以看成int类型的地址

arduino 发送float类型数据

float b=(float)millis() / 1000.0;

Serial2.write( ((byte*) &b),4);
//Serial2.flush();
delay(100);

最新文章

  1. codevs 1228 苹果树 树链剖分讲解
  2. yii2史上最简单式安装教程,没有之一
  3. 【Java源码分析】LinkedList类
  4. While reading xxx.png pngcrush caught libpng error: Not a PNG file..
  5. webpack打包sass
  6. java中关于移位运算符的demo与总结
  7. 微信--高效解决token及授权用户openid的持久化处理办法
  8. Bootstrap入门(二十三)JS插件1:模态框
  9. C语言获取系统时间的函数
  10. ArrayList源码分析超详细
  11. vue.js数据可以在页面上渲染成功却总是警告提示某个字段“undefined”未定义
  12. 201771010118《面向对象程序设计(java)》第三周学习总结
  13. RNP项目遇到的坑
  14. 【原创】大叔经验分享(36)CM部署kafka
  15. 建立标准编码规则(二)-DiagnosticAnalyzer 增加诊断分析代码
  16. Xgboost理解
  17. css3常用动画样式文件move.css
  18. JavaScript中的坑
  19. jq03--基础函数
  20. Python之路,Day2 - Python基础,列表,循环

热门文章

  1. Oracle 11g超详细安装步骤
  2. 使用sql获取primary key名称
  3. 抽象类(abstract class)
  4. 格式化java8 LocalDateTime
  5. while循环出现的问题
  6. #define宏常量和const常量的区别
  7. centos自定义安装pip3
  8. 乱序字符串anagrams
  9. jQuery之双下拉框
  10. centos7之iptables与firewalld