- 浏览: 169333 次
- 性别:
- 来自: 青岛
文章分类
最新评论
-
hugang357:
...
java String to byte[] -
lyzhu:
winstr
使用JAVASCRIPT实现弹出框,过一段时间自动消失 -
laoliu.org:
要是稍微整理一下成一个健全类就更好了,呵呵。
我把它转到IT民 ...
java月份时间(第一天,最后一天) -
kaituozhe6666:
...
使用JAVASCRIPT实现弹出框,过一段时间自动消失 -
damocreazy:
试一试
如何让EditPlus可以编译执行Java程序
引用 http://www.javaresearch.org/article/83622.htm
- package com.test;
- import java.nio.ByteBuffer;
- public class ByteUtil {
- /**
- * @param args
- */
- public static void main(String[] args) {
- test2();
- }
- public static void test2()
- {
- short s = -20;
- byte[] b = new byte[2];
- putReverseBytesShort(b, s, 0);
- ByteBuffer buf = ByteBuffer.allocate(2);
- buf.put(b);
- buf.flip();
- System.out.println(getReverseBytesShort(b, 0));
- System.out.println(Short.reverseBytes(buf.getShort()));
- System.out.println("***************************");
- int i = -40;
- b = new byte[4];
- putReverseBytesInt(b, i, 0);
- buf = ByteBuffer.allocate(4);
- buf.put(b);
- buf.flip();
- System.out.println(getReverseBytesInt(b, 0));
- System.out.println(Integer.reverseBytes(buf.getInt()));
- System.out.println("***************************");
- long l = -50;
- b = new byte[8];
- putReverseBytesLong(b, l, 0);
- buf = ByteBuffer.allocate(8);
- buf.put(b);
- buf.flip();
- System.out.println(getReverseBytesLong(b, 0));
- System.out.println(Long.reverseBytes(buf.getLong()));
- System.out.println("***************************");
- }
- public static void test1()
- {
- short s = -20;
- byte[] b = new byte[2];
- putShort(b, s, 0);
- ByteBuffer buf = ByteBuffer.allocate(2);
- buf.put(b);
- buf.flip();
- System.out.println(getShort(b, 0));
- System.out.println(buf.getShort());
- System.out.println("***************************");
- int i = -40;
- b = new byte[4];
- putInt(b, i, 0);
- buf = ByteBuffer.allocate(4);
- buf.put(b);
- buf.flip();
- System.out.println(getInt(b, 0));
- System.out.println(buf.getInt());
- System.out.println("***************************");
- long l = -50;
- b = new byte[8];
- putLong(b, l, 0);
- buf = ByteBuffer.allocate(8);
- buf.put(b);
- buf.flip();
- System.out.println(getLong(b, 0));
- System.out.println(buf.getLong());
- System.out.println("***************************");
- }
- public static void putShort(byte b[], short s, int index) {
- b[index] = (byte) (s >> 8);
- b[index + 1] = (byte) (s >> 0);
- }
- public static void putReverseBytesShort(byte b[], short s, int index) {
- b[index] = (byte) (s >> 0);
- b[index + 1] = (byte) (s >> 8);
- }
- public static short getShort(byte[] b, int index) {
- return (short) (((b[index] << 8) | b[index + 1] & 0xff));
- }
- public static short getReverseBytesShort(byte[] b, int index) {
- return (short) (((b[index+1] << 8) | b[index] & 0xff));
- }
- // ///////////////////////////////////////////////////////
- public static void putInt(byte[] bb, int x, int index) {
- bb[index + 0] = (byte) (x >> 24);
- bb[index + 1] = (byte) (x >> 16);
- bb[index + 2] = (byte) (x >> 8);
- bb[index + 3] = (byte) (x >> 0);
- }
- public static void putReverseBytesInt(byte[] bb, int x, int index) {
- bb[index + 3] = (byte) (x >> 24);
- bb[index + 2] = (byte) (x >> 16);
- bb[index + 1] = (byte) (x >> 8);
- bb[index + 0] = (byte) (x >> 0);
- }
- public static int getInt(byte[] bb, int index) {
- return (int) ((((bb[index + 0] & 0xff) << 24)
- | ((bb[index + 1] & 0xff) << 16)
- | ((bb[index + 2] & 0xff) << 8) | ((bb[index + 3] & 0xff) << 0)));
- }
- public static int getReverseBytesInt(byte[] bb, int index) {
- return (int) ((((bb[index + 3] & 0xff) << 24)
- | ((bb[index + 2] & 0xff) << 16)
- | ((bb[index + 1] & 0xff) << 8) | ((bb[index + 0] & 0xff) << 0)));
- }
- // /////////////////////////////////////////////////////////
- public static void putLong(byte[] bb, long x, int index) {
- bb[index + 0] = (byte) (x >> 56);
- bb[index + 1] = (byte) (x >> 48);
- bb[index + 2] = (byte) (x >> 40);
- bb[index + 3] = (byte) (x >> 32);
- bb[index + 4] = (byte) (x >> 24);
- bb[index + 5] = (byte) (x >> 16);
- bb[index + 6] = (byte) (x >> 8);
- bb[index + 7] = (byte) (x >> 0);
- }
- public static void putReverseBytesLong(byte[] bb, long x, int index) {
- bb[index + 7] = (byte) (x >> 56);
- bb[index + 6] = (byte) (x >> 48);
- bb[index + 5] = (byte) (x >> 40);
- bb[index + 4] = (byte) (x >> 32);
- bb[index + 3] = (byte) (x >> 24);
- bb[index + 2] = (byte) (x >> 16);
- bb[index + 1] = (byte) (x >> 8);
- bb[index + 0] = (byte) (x >> 0);
- }
- public static long getLong(byte[] bb, int index) {
- return ((((long) bb[index + 0] & 0xff) << 56)
- | (((long) bb[index + 1] & 0xff) << 48)
- | (((long) bb[index + 2] & 0xff) << 40)
- | (((long) bb[index + 3] & 0xff) << 32)
- | (((long) bb[index + 4] & 0xff) << 24)
- | (((long) bb[index + 5] & 0xff) << 16)
- | (((long) bb[index + 6] & 0xff) << 8) | (((long) bb[index + 7] & 0xff) << 0));
- }
- public static long getReverseBytesLong(byte[] bb, int index) {
- return ((((long) bb[index + 7] & 0xff) << 56)
- | (((long) bb[index + 6] & 0xff) << 48)
- | (((long) bb[index + 5] & 0xff) << 40)
- | (((long) bb[index + 4] & 0xff) << 32)
- | (((long) bb[index + 3] & 0xff) << 24)
- | (((long) bb[index + 2] & 0xff) << 16)
- | (((long) bb[index + 1] & 0xff) << 8) | (((long) bb[index + 0] & 0xff) << 0));
- }
}
发表评论
-
java调用google map api 根据经纬度读取经纬度地址
2012-02-28 08:42 2779package B7.general; import ... -
java 读取http url joson 格式
2012-02-28 08:39 1137URL url = new URL("htt ... -
【转】用Lucene的SpellChecker实现Google的“您是不是要找”功能
2011-03-25 11:01 1421引言 很多人在使用搜索引擎的时候,会出于各种原因,拼错想要搜 ... -
Java 接口和抽象类区别
2011-03-02 08:58 570一个软件设计的好坏, ... -
php 环境搭建
2009-06-17 17:25 1090想学习php。在网上找了个搭建。好多杂的。google一下时间 ... -
abstract class vc interface
2008-12-10 16:24 1413abstract class 和 interface 都提供可 ... -
二分查找vc线性查找
2008-12-10 14:32 1026public static int binarySearch( ... -
java 取字符串中汉字之前的部门
2008-09-03 17:28 1037String dd="ddfdf你好" ... -
java 数组 操作
2008-08-21 17:30 1035public ArrayList zuhe(){ ... -
查询代码网站
2008-08-17 15:55 742<search terms> Search fo ... -
java String to byte[]
2008-07-16 09:01 4430package mobile; /* * T ... -
java pdf
2008-07-13 13:39 1107引用 :http://www.iteye.com/post/5 ... -
java月份时间(第一天,最后一天)
2008-06-13 20:57 7024<% //当前月的最后一天 ... -
java中文件操作大全
2008-05-08 18:07 956引用: http://www.pben.cn/main.bb ... -
较好的Java网站收集
2008-04-25 14:19 936转自:http://blog.chinaunix. ... -
java 自定义排序
2008-04-21 10:21 2003利用java.util. Comparator接口 和java ... -
2008年Java开发者最迫切的五个期望
2008-03-29 11:28 1193发布日期:2008-1-11 9:11 ... -
Java精华积累:每个初学者都应该搞懂的问题!
2008-03-07 13:20 1021Java精华积累:每个初学 ... -
如何让EditPlus可以编译执行Java程序
2008-02-13 10:51 1712如何让EditPlus可以编译执行Java程序在 USER T ... -
阴阳转换的类! 算法支持1900-2050
2008-02-13 10:49 1271引自: http://www.nqqn.com/ym/68/2 ...
相关推荐
ip地址转4字节byte,char转2字节byte,byte数组转char,int整数转换为4字节的byte数组,byte数组转换为int整数,double类型转8字节数组,8位数组转double,long整数转换为8字节的byte数组,short整数转换为2字节的...
char short int long float double 转换成byte数组
下面小编就为大家带来一篇java byte数组与int,long,short,byte的转换实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
byte数组转换为int 保留几位小数 null转String String转Byte String转Boolean String转Int String转Short String转Double Int转String Double转Long Double转Int Long转Double Long转Int String转Long Long转String
举例分析 equals 和 hashcode 方法,hashcode应该怎么样生成 8个基本类型与基本对象的比较:byte与Byte shot与Short int与Integer long与Long float与Float double与Double char与Character
字节转换什么事啊您是否曾经想过通过I2C,SPI,串行或其他协议或总线传输int , short , long , double或任何其他数字类型,但是您已将变量转换为字符串以能够按char进行传输。 该库使您可以将任何数值转换为字节...
float、double等类型与byte数组相互转换,根据数据类型的位数不同,对应的数组大小也不同、例如int32位,4个字节,则需要大小为4的byte数组来进行转换,详情请看代码,里面有转换的实现和详细的注释
byte→short(char)→int→long→float→double 也就是说byte类型的变量可以自动转换为short类型,示例代码: byte b = 10; short sh = b; 这里在赋值时,JVM首先将b的值转换为short类型,然后再赋值给sh。 在类型...
在java中的整数类型有四种,分别是byte short in long,本文重点给大家介绍java中的整数类型(short int long),由于byte只是一个字节0或1,在此就不多说了,对java中的整数类型感兴趣的朋友一起学习吧
一些初学JAVA的朋友可能会遇到JAVA的数据类型之间转换的苦恼,例如,整数和float,double型之间的转换,整数和String类型之间的转换,以及处理、显示时间方面的问...byte、short、int、long;浮点型float、double。其
在switch(expr1)中,expr1只能是一个整数表达式或者枚举常量(更大字体),整数表达式可以是int基本类型或Integer包装类型,由于,byte,short,char都可以隐含转换为int,所以,这些类型以及这些类型的包装类型也...
[signed] short [int] 2Byte unsigned short [int] 2 Byte long [int] 4 Byte unsigned long [int] 4 Byte Visual C++ 6.0: [signed] int 4Byte unsigned int 4Byte [signed] short [in
byte→short(char)→int→long→float→double 也就是说byte类型的变量可以自动转换为short类型,示例代码: byte b = 10; short sh = b; 在类型转换时可以跳跃。示例代码: byte b1 = 100; int n = b1; ...
当需要把某个属性值或者文本块内容转换为int、short、long时,不需要先把byte数组转化成string,然后再转化成int、short、long。FastXml直接把byte数组转换成对应的类型。 如果xml文档中有些标签内容你并...
(1)基本类型 byte short int long float double char boolean (2)引用类型 类 数组 接口 枚举 注解 变量:内存中的一块存储空间, 存储的就是常量。 特点:一个变量只能存储一个数据,不能存储多个。 需求:...
int HufBlock(BYTE dchufindex,BYTE achufindex); int DecodeElement(); BYTE ReadByte(); int WaterMarkExtractDecode(); void IQtIZzMCUComponent(short flag); void IZzMCUComponent(short flag); void ...
byte short int long 的关系
基本整数类型包括Shortint、Smallint、Longint、Int64、Byte、Word、Longword等,如下: 类型 范围 格式 Shortint -128..127 含符号的8位 Smallint -32768..32767 含符号的16位 Longint -2147483648...
在linux下,将uyvy格式的图片转换成bmp格式 默认宽度是720 头文件忘记传了:uyvytobmp.h #ifndef __UYVY_TO_BMP__ #define __UYVY_TO_BMP__ typedef unsigned int DWORD; typedef unsigned short int WORD; typedef...
键盘输入1个字符串,如果是整数数字串,如”4353”, 分别按八进制和十六进制输出,以及按byte,short,int,long,char输出;每个数占10位长.每行输出3个数; 如果是带小数数字串,如”243.58”,分别按short,int,long,float...