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);

浮点数转byte数组的更多相关文章

  1. int跟byte[]数组互转的方法,整数 + 浮点型

    整数: int转byte数组 public static byte[] intToBytes2(int n){ ]; ;i < ;i++) { b[i]=(-i*)); } return b; ...

  2. go语言:多个[]byte数组合并成一个[]byte

    场景:在开发中,要将多个[]byte数组合并成一个[]byte,初步实现思路如下: 1.获取多个[]byte长度 2.构造一个二维码数组 3.循环将[]byte拷贝到二维数组中 package gst ...

  3. byte数组和File,InputStream互转

    1.将File.FileInputStream 转换为byte数组: File file = new File("file.txt"); InputStream input = n ...

  4. C# byte数组与Image的相互转换

    功能需求: 1.把一张图片(png bmp jpeg bmp gif)转换为byte数组存放到数据库. 2.把从数据库读取的byte数组转换为Image对象,赋值给相应的控件显示. 3.从图片byte ...

  5. 透过byte数组简单分析Java序列化、Kryo、ProtoBuf序列化

    序列化在高性能网络编程.分布式系统开发中是举足轻重的之前有用过Java序列化.ProtocolBuffer等,在这篇文章这里中简单分析序列化后的byte数组观察各种序列化的差异与性能,这里主要分析Ja ...

  6. 字符串与byte数组转换

    string weclome=""; byte[] data = new byte[1024]; //字符串转byte数组 data = Encoding.ASCII.GetByt ...

  7. C# 将文件转化成byte[]数组

    /// <summary> /// 将文件转换成byte[] 数组 /// </summary> /// <param name="fileUrl"& ...

  8. Java 文件和byte数组转换

    /** * 获得指定文件的byte数组 */ private byte[] getBytes(String filePath){ byte[] buffer = null; try { File fi ...

  9. InputStream,BufferedImage与byte数组之间的转换

    需要获取网络的一张图片,但是某种需要,要把获取的这段流输入换为BufferedImage流,有的地方还需要转换为byte[]. 获得图片地址,获得了一个图片输入流,例如:    Url img = n ...

随机推荐

  1. VS 类快捷键

    生成类的构造函数 输入 ctrl,按两下 TAB 键 快速添加属性输入prop,按2下tab键 添加折叠输入reg,按2下tab键,快速输入#region输入class,按下2次tab建,快速输入类定 ...

  2. XE4 TStringDynArray 比 c6 的TStringList 好用 字符串 分解 分割 转换 TByteDynArray

    TStringDynArray 动态数组  字符串 分解 分割  System::DynamicArray<System::UnicodeString> TByteDynArray,    ...

  3. 修改thinkpad 小红点(TrackPoint速度)

    from: http://www.jianshu.com/p/b9677e9e56ec Thinkpad大概是对Linux支持最好的笔记本了,Ubuntu大概是对硬件支持最好的Linux发行版了.Ub ...

  4. TEXT 15 A text a day...

    TEXT 15 A text a day... Mar 24th 2006 From The Economist print edition The medical uses of mobile ph ...

  5. Servlet Response 重定向

    重定向 response.sendRedirect("index.jsp");       //登录用户名不存在,重定向到index.jsp 1重定向在客户端发挥作用,通过浏览器重 ...

  6. 数据库索引&数据页

    索引的好处 索引带来的益处可能很多读者会认为只是"能够提高数据检索的效率,降低数据库的IO成本". 确实,在数据库中表的某个字段创建索引,所带来的最大益处就是将该字段作为检索条件时 ...

  7. idea 安装uml 画图工具

    centos7上: yum -y install graphviz mac上: brew install Graphviz file -> setting->plugins 安装plant ...

  8. intellij idea 添加模板语句

    1.说明 在intellij idea 中有很多模板语句可有使用,比如:输入sout,就可以直接生成 System.out.println();代码, 输入psvm,就可以直接生成main方法,类似这 ...

  9. Docker Dockerfile 定制镜像(转)

    转自: https://yeasy.gitbooks.io/docker_practice/ 及 https://blog.csdn.net/wo18237095579/article/details ...

  10. Array Product(模拟)

    Array Product http://codeforces.com/problemset/problem/1042/C You are given an array aa consisting o ...