1. /*将int转为低字节在前,高字节在后的byte数组
  2.  
    b[0] = 11111111(0xff) & 01100001
  3.  
    b[1] = 11111111(0xff) & (n >> 8)00000000
  4.  
    b[2] = 11111111(0xff) & (n >> 8)00000000
  5.  
    b[3] = 11111111(0xff) & (n >> 8)00000000
  6.  
    */
  7.  
    public byte[] IntToByteArray(int n) {
  8.  
    byte[] b = new byte[4];
  9.  
    b[0] = (byte) (n & 0xff);
  10.  
    b[1] = (byte) (n >> 8 & 0xff);
  11.  
    b[2] = (byte) (n >> 16 & 0xff);
  12.  
    b[3] = (byte) (n >> 24 & 0xff);
  13.  
    return b;
  14.  
    }
  15.  
    //将低字节在前转为int,高字节在后的byte数组(与IntToByteArray1想对应)
  16.  
    public int ByteArrayToInt(byte[] bArr) {
  17.  
    if(bArr.length!=4){
  18.  
    return -1;
  19.  
    }
  20.  
    return (int) ((((bArr[3] & 0xff) << 24)
  21.  
    | ((bArr[2] & 0xff) << 16)
  22.  
    | ((bArr[1] & 0xff) << 8)
  23.  
    | ((bArr[0] & 0xff) << 0)));
  24.  
    }
    1. public static byte[] double2Bytes(double d) {
    2.  
      long value = Double.doubleToRawLongBits(d);
    3.  
      byte[] byteRet = new byte[8];
    4.  
      for (int i = 0; i < 8; i++) {
    5.  
      byteRet[i] = (byte) ((value >> 8 * i) & 0xff);
    6.  
      }
    7.  
      return byteRet;
    8.  
      }
       
      1. public static double bytes2Double(byte[] arr) {
      2.  
        long value = 0;
      3.  
        for (int i = 0; i < 8; i++) {
      4.  
        value |= ((long) (arr[i] & 0xff)) << (8 * i);
      5.  
        }
      6.  
        return Double.longBitsToDouble(value);
      7.  
        }

byteArray转换为double,int的更多相关文章

  1. C语言atof()函数:将字符串转换为double(双精度浮点数)

    头文件:#include <stdlib.h> 函数 atof() 用于将字符串转换为双精度浮点数(double),其原型为:double atof (const char* str); ...

  2. 程序里面带有浮点数,默认会自动转换为double类型存储

    带有浮点数,默认会转换为double类型存储. #include "common.h" #include <stdio.h> #include <stdlib.h ...

  3. 将 expression 转换为数据类型 int 时发生算术溢出

    将 expression 转换为数据类型 int 时发生算术溢出错误 2种快速处理方法 1.CONVERT(bigint, 字段名): 2.Cast(字段名 as decimal(18,2)): 这个 ...

  4. 将 IDENTITY 转换为数据类型 int 时出现算术溢出错误。

    IDENTITY标识列为int类型,取值范围为-2^32到2^31-1.当增长值超过这个最大值时,我在SQL Server 2008 R2 x64上试验的结果是: 将 IDENTITY 转换为数据类型 ...

  5. sql servel 报错:将 expression 转换为数据类型 int 时出现算术溢出错误。

    执行sql语句:SELECT   AVG( DATEDIFF(s,s.CreatedDate,s.SendDate)  ) AS submitTime FROM dbo.SmsSend AS s    ...

  6. 【转载】C#中使用double.TryParse方法将字符串转换为double类型

    在C#编程过程中,将字符串string转换为double类型过程中,时常使用double.Parse方法,但double.Parse在无法转换的时候,会抛出程序异常,其实还有个double.TryPa ...

  7. 【转载】C#中Convert.ToDouble方法将字符串转换为double类型

    在C#编程过程中,可以使用Convert.ToDouble方法将字符串或者其他可转换为数字的对象变量转换为double类型,Convert.ToDouble方法有多个重载方法,最常使用的一个方法将字符 ...

  8. DataTable 中varchar 转换为 Double 后重新 排序。

    DataTable  查询出某个字段为varchar 类型的.不过里面存的为数字,需要进行排序.可是如果直接排序就会不对.因为为varchar类型的,需要转换一下. 方法一: dt.Columns.A ...

  9. double int char 数据类型

    贴心的limits... 测试代码: #include <iostream> #include <stdio.h> #include <limits> #inclu ...

随机推荐

  1. T2695 桶哥的问题——吃桶

    ~~~~~我~是~真的~忍不了~这个~取模~的~锅~了~~~~~ T2695 桶哥的问题——吃桶 前传 1.T2686 桶哥的问题——买桶 这题真的hin简单,真的 2.T2691 桶哥的问题——送桶 ...

  2. defineProperty

    ### Object.defineProperty() https://segmentfault.com/a/1190000007434923方法会直接在一个对象上定义一个新属性,或者修改一个已经存在 ...

  3. 算法 - 剪枝游戏 - Green Hackenbush

    场景:给颗树,轮流剪掉一条枝,没枝可剪的人输. 题目:Deforestation | HackerRank 讲解:Games!: Green Hackenbush 哎,差点自己想出来答案,最后还是看了 ...

  4. 代码实现:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。

    import java.util.ArrayList; import java.util.List; import java.util.Scanner; //有n个人围成一圈,顺序排号.从第一个人开始 ...

  5. Appium+python自动化-输入中文

    一.定位搜索 1.打开淘宝点击搜索按钮,进入到搜索页面 2.然后定位到搜索框后用sendkeys方法输入‘hao’,这里定位元素使用uiautomatorviewer工具即可 3.脚本如下,输入的是英 ...

  6. nmon服务器监控工具的使用安装

    nmon是一个监控服务器性能的工具 目录 1.安装nmon 2.数据采集 1.安装nmon nmon是一种linux服务器性能监控工具,他还提供了很好的图表结果展示功能.本篇以centos6.5系统为 ...

  7. vmware虚拟机设置时区、时间

    首先查看时间发现和百度的时间不一样 [root@www ~]# dateWed Dec 5 14:00:32 CST 2018 1.配置ntp服务器,设置时区同步,请参照ntp篇  https://w ...

  8. 查询sq字段逗号分隔的方式

    2,3,4 -- select * from t_qs_anlycomagingconfig twhere and ( to_char(','||t.valid_month||',') like '% ...

  9. cocos2dx[3.2](5) 屏幕适配

    1.两个分辨率 1.1.窗口分辨率 在AppDelegate.cpp中有个设置窗口分辨率的函数.该函数是设置了我们预想设备的屏幕大小,也就是应用程序窗口的大小. // glView->setFr ...

  10. jquery实现分页效果

    通过jq实现分页的原理如下:将所有条数加载到页面中,根据每页放特定条数(例如 5 条)获取jquery对象索引,使部分条数显示,其他条数隐藏. 前提:引入jquery.js 代码 <!DOCTY ...