java int转byte数组
int 转 byte[] 低字节在前(低字节序)
public static byte[] toLH(int n) {
byte[] b = new byte[4];
b[0] = (byte) (n & 0xff);
b[1] = (byte) (n >> 8 & 0xff);
b[2] = (byte) (n >> 16 & 0xff);
b[3] = (byte) (n >> 24 & 0xff);
return b;
}
int 转 byte[] 高字节在前(高字节序)
public static byte[] toHH(int n) {
byte[] b = new byte[4];
b[3] = (byte) (n & 0xff);
b[2] = (byte) (n >> 8 & 0xff);
b[1] = (byte) (n >> 16 & 0xff);
b[0] = (byte) (n >> 24 & 0xff);
return b;
}
byte[] 转 int 低字节在前(低字节序)
public int toInt(byte[] b){
int res = 0;
for(int i=0;i<b.length;i++){
res += (b[i] & 0xff) << (i*8);
}
return res;
}
byte[] 转 int 高字节在前(高字节序)
public static int toInt(byte[] b){
int res = 0;
for(int i=0;i<b.length;i++){
res += (b[i] & 0xff) << ((3-i)*8);
}
return res;
}
java int转byte数组的更多相关文章
- Redis入门 – Jedis存储Java对象 - (Java序列化为byte数组方式)
Redis入门 – Jedis存储Java对象 - (Java序列化为byte数组方式) 原文地址:http://alanland.iteye.com/admin/blogs/1600685(欢迎转载 ...
- int跟byte[]数组互转的方法,整数 + 浮点型
整数: int转byte数组 public static byte[] intToBytes2(int n){ ]; ;i < ;i++) { b[i]=(-i*)); } return b; ...
- Java 基础类型转换byte数组, byte数组转换基础类型
Java 基础类型转换byte数组, byte数组转换基础类型 Java类型转换 java类对象转化为byte数组
- Java 文件和byte数组转换
/** * 获得指定文件的byte数组 */ private byte[] getBytes(String filePath){ byte[] buffer = null; try { File fi ...
- java int转byte和long转byte
在网络编程中,出于节约带宽或者编码的需要,通常需要以原生方式处理long和int,而不是转换为string. public class ByteOrderUtils { public static b ...
- Java 图片与byte数组互相转换
//图片到byte数组 public byte[] image2byte(String path){ byte[] data = null; FileImageInputStream input = ...
- java File和Byte[]数组 相互转换
public class Test { public static void main(String[] args){ String filePath = "E:\\softoon\\wor ...
- Java官方操纵byte数组的方式
java官方提供了一种操作字节数组的方法——内存流(字节数组流)ByteArrayInputStream.ByteArrayOutputStream ByteArrayOutputStream——by ...
- JAVA获取文件byte数组并输出进行展示和文件下载
/** * 文件下载 */ @GetMapping(value = "/download") public void download(HttpServletResponse re ...
- 深入 JAVA里面关于byte数组和String之间的转换问题
把byte转化成string,必须经过编码. 例如下面一个例子: importjava.io.UnsupportedEncodingException; publicclass test{ pub ...
随机推荐
- v-if 为什么不能和 v-for 一起使用 ?
当 Vue 处理指令时,v-for 比 v-if 具有更高的优先级,通过v-if 移动到容器元素,不会再重复遍历列表中的每个值.取而代之的是,我们只检查它一次,且不会在 v-if 为否的时候运算 v- ...
- maven的pom.xml基础配置
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...
- 说一下tcp三次握手
1. 客户端发送syn请求连接 : 2. 服务器检验syn,然后发送syn和ack确认连接: 3. 客户端接收ack和syn,然后发送ack建立连接 :
- 华为OpenEnler Linux系统部署LNMP
LNMP是Linux+Nginx+Mysql+PHP所构建的一个动态开发环镜 我这里使用的系统是华为的OpenEnler系统,使用了Nginx1.12版本.Mysql8和PHP7.4 如果有出错的地方 ...
- Shadcn UI:现代前端的灵活组件库
简要介绍 Shadcn UI 与其他 UI 和组件库如 Material UI.Ant Design.Element UI 的设计理念截然不同.这些库一般通过 npm 包提供对组件的访问,而 Shad ...
- es安全认证search-guard配置
大数据安全系列的其它文章 https://www.cnblogs.com/bainianminguo/p/12548076.html-----------安装kerberos https://www. ...
- Nuxt.js 应用中的 build:error 事件钩子详解
title: Nuxt.js 应用中的 build:error 事件钩子详解 date: 2024/11/7 updated: 2024/11/7 author: cmdragon excerpt: ...
- Typora实现双击图片放大 Mac
前置条件 Typora LightBox: github下载 添加LightBox拓展 打开应用程序,找到typora,右键选择"显示包内容". 解压lightbox2代码,将di ...
- 7. jenkins的代码审查
sonar基本使用 1,sonar安装和配置 SonarQube是一个用于管理代码质量的开放平台,可以快速的定位代码中潜在的或者明显的错误.目前 支持java,C#,C/C++,Python,PL/S ...
- win10子系统docker搭建gitlab Server
心血来潮想搞一套cicd玩玩,结果开始就掉坑里了. 遇到问题 不会写文,所以语言组织比较差,将就看着吧!就当记录一下这个坑以后没准还能用的上. 参照https://blog.csdn.net/Mono ...