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. day7_集合,深浅copy

    一.集合 集合是无序的,不重复的数据集合,其元素为可哈希(不可变类型),但是集合本身是不可哈希(所以集合做不了字典的键).以下是集合最重要的两点: 去重,把一个列表变成集合,就自动去重了. 关系测试, ...

  2. golang网络通信超时设置

    网络通信中,为了防止长时间无响应的情况,经常会用到网络连接超时.读写超时的设置. 本文结合例子简介golang的连接超时和读写超时设置. 1.超时设置 1.1 连接超时 func DialTimeou ...

  3. virtualbox安装xp虚拟机缺少驱动

    下载驱动精灵完全版,自带万能驱动

  4. [VBA]汇总多个工作簿的指定工作表到同一个工作簿的指定工作表中

    sub 汇总多个工作簿() Application.ScreenUpdating = False Dim wb As Workbook, f As String, l As String, n As ...

  5. nginx不记录指定文件类型的日志

    1.指定记录文件日志记录的内容. vim /usr/local/nginx/conf/nginx.conf如下部分: log_format dd '$remote_addr $http_x_forwa ...

  6. Java学习之==>数组【array】

    一.定义数组 /** * 一维数组定义 * * 为数组插入元素 */ public void case1() { // 声明 int[] arr1; // 声明+初始化 int[] arr2 = ne ...

  7. c++ 函数后面有个 const

    非静态成员函数后面加const,类似如下函数: class testClass{ public: void testClass() const{ /*...*/} private: /*...*/ } ...

  8. Spring容器启动源码分析

    1. 前言 最近搭建的工程都是基于SpringBoot,简化配置的感觉真爽.但有个以前的项目还是用SpringMvc写的,看到满满的配置xml文件,却有一种想去深入了解的冲动.折腾了好几天,决心去写这 ...

  9. 浏览器访问ipv6站点(未绑定主机的ipv6站点)

    我们在浏览器直接输入ipv6地址敲回车,一般情况下浏览器会跳转到搜索引擎进行搜索. 我们需要在浏览器器中输入: http://[::1]  或者 [::1]

  10. DJANGO MODEL FORMSETS IN DETAIL AND THEIR ADVANCED USAGE

    Similar to the regular formsets, Django also provides model formset that makes it easy to work with ...