当前位置: 首页 > news >正文

网站开发增值税税率是多少百度seo关键词排名s

网站开发增值税税率是多少,百度seo关键词排名s,网站设计简单吗,门户网站建设自查整改报告文章目录 前言一、无符号字节转为int1.前置知识2.无符号转int代码3.Java中字节转为int 二、字节缓冲流1.基础知识2.String与ByteBuffer转换 总结 前言 Java 中基本类型都是有符号数值,如果接收到了 C/C 处理的无符号数值字节流,将出现转码错误。 提示&a…

文章目录

  • 前言
  • 一、无符号字节转为int
    • 1.前置知识
    • 2.无符号转int代码
    • 3.Java中字节转为int
  • 二、字节缓冲流
    • 1.基础知识
    • 2.String与ByteBuffer转换
  • 总结


前言

Java 中基本类型都是有符号数值,如果接收到了 C/C++ 处理的无符号数值字节流,将出现转码错误。


提示:以下是本篇文章正文内容,下面案例可供参考

一、无符号字节转为int

1.前置知识

在线进制转换:https://tool.oschina.net/hexconvert
之前在解析 webscoket 传输得二进制数据时,因为二进制数据传输的是 uint32 无符号整数,需要把有符号的字节转为正常的;
uint32 代表无符号整数,只能存正整数,在内存中占4个字节,byte[4],0到4294967295,Java中 int 为32位有符号整数,占4字节,-2147483648 到 2147483648。

2.无符号转int代码

public static long bytes2int(byte[] buf){long anUnsignedInt = 0;int firstByte = 0;int sceondByte = 0;int thirdByte = 0;int fourthByte = 0;int index = 0;firstByte = (0x000000FF & ((int) buf[index+3]));sceondByte = (0x000000FF & ((int) buf[index+2]));thirdByte = (0x000000FF & ((int) buf[index+1]));fourthByte = (0x000000FF & ((int) buf[index]));anUnsignedInt = ((long) (firstByte << 24 | sceondByte << 16 | thirdByte << 8 | fourthByte)) & 0xFFFFFFFFL;return anUnsignedInt ;
}

3.Java中字节转为int

public static int byteArrayToInt(byte[] bytes) {int n = 0;for (int i = 0; i < 4; i++) {n += bytes[i] << i*8;}return n;
}

二、字节缓冲流

1.基础知识

  • 分配一个指定大小的缓冲区
// 1.分配一个指定大小的缓冲区
ByteBuffer buf = ByteBuffer.allocate(1024);
System.out.println(buf.position); 	//0
System.out.println(buf.limit); 		//1024
System.out.println(buf.capacity); 	//1024
System.out.println(buf.mark); 
  • 利用put()方法进行存储数据
// 2.利用put()方法进行存储数据
String str = "hello nio";
buf.put(str.getBytes());
System.out.println(buf.position); 	//9
System.out.println(buf.limit); 		//1024
System.out.println(buf.capacity); 	//1024
System.out.println(buf.mark); 
  • 切换读取数据的模式
// 3.切换读取数据的模式
buf.flip();
System.out.println(buf.position); 	//0
System.out.println(buf.limit); 		//1024
System.out.println(buf.capacity); 	//1024
System.out.println(buf.mark);
  • 利用get()方法读取数据
// 4.利用get()方法读取数据
byte[] dst = new byte[buf.limit()];
buf.get(dst);
System.out.println(new String(dst, 0, dst.lenth));System.out.println(buf.position); 	//9
System.out.println(buf.limit); 		//9
System.out.println(buf.capacity); 	//1024
System.out.println(buf.mark

2.String与ByteBuffer转换

import java.nio.ByteBuffer;  
import java.nio.CharBuffer;  
import java.nio.charset.Charset;  
import java.nio.charset.CharsetDecoder;  public class Test {  /** * String 转换 ByteBuffer * @param str * @return */  public static ByteBuffer getByteBuffer(String str) {  return ByteBuffer.wrap(str.getBytes());  }  /** * ByteBuffer 转换 String * @param buffer * @return */  public static String getString(ByteBuffer buffer) {  Charset charset = null;  CharsetDecoder decoder = null;  CharBuffer charBuffer = null;  try {  charset = Charset.forName("UTF-8");  decoder = charset.newDecoder();  // charBuffer = decoder.decode(buffer);//用这个的话,只能输出来一次结果,第二次显示为空  charBuffer = decoder.decode(buffer.asReadOnlyBuffer());  return charBuffer.toString();  }  catch (Exception ex) {  ex.printStackTrace();  return "";  }  }  
}

总结

生活, 一半是回忆, 一半是继续。 把所有的不快给昨天, 把所有的希望给明天, 把所有的努力给今天。

在这里插入图片描述

http://www.mmbaike.com/news/37936.html

相关文章:

  • 杭州门户网站有哪些网站诊断工具
  • 自己做聊天背景网站手机百度推广怎么打广告
  • 建设商城网站公司吗外贸网络营销
  • 搜索关键词网站友情链接作用
  • 创建wordpress小工具南昌seo管理
  • 变更备案提示 网站主办者冲突手机百度搜索app
  • 国外做免费网站的中国十大小说网站排名
  • 一个做问卷调查的网站100个裂变营销案例
  • 无锡有人代做淘宝网站吗百度云官网首页
  • 男人不知本网站 枉做网站查询平台
  • 劳务公司网站怎么做药品网络营销公司
  • 河南网站建设公司价格小红书推广引流软件
  • 达人室内设计网怎么免费注册深圳seo优化电话
  • 桂林网站建设动服卖照明电源设推广方案的推广内容怎么写
  • 聊城seo整站优化报价引擎优化seo
  • 可以做网络兼职的网站seo学校培训课程
  • 网站建设内容与结构阿里指数查询官网
  • 惠州做网站乐云seo轻松上线百度收录官网
  • 监控设备东莞网站建设优化大师百科
  • 有没有做校园文化的网站小程序推广赚佣金平台
  • 网站建设及维护价钱网店运营具体做什么
  • 网站建设缺乏个性特色产品推广方案
  • 国外图片网站源码西安小程序开发的公司
  • 宝塔里面一个服务器做多个网站百度数据研究中心
  • 三个小伙毕业了做购物网站的电视剧微营销推广方案
  • 网页制作软件visual网站关键词快速排名优化
  • 网站开发常用语言比较高端网站建设公司
  • 长沙网站建设公司哪家好外贸seo优化公司
  • php做的大型网站有哪些整合营销传播工具有哪些
  • 东莞百度代做网站联系方式燕郊今日头条