java c 数据类型转换_Java与C底层数据类型转换(Java and C underlying data type conversion).doc...

Java与C底层数据类型转换(Java and C underlying data type conversion)

Java与C底层数据类型转换(Java and C underlying data type conversion)

进口java.io.bytearrayinputstream;

进口java.io.bytearrayoutputstream;

进口java.io.datainputstream;

进口java.io.dataoutputstream;

进口;

/ * *

*仅仅适用于java与C++通讯中,网络流解析与生成使用

*

*高低位互换(大端大头在前&小端小头在前)。

*举例而言,有一个4字节的数据0要存储在内存中或文件中编号0~3字节的位置,两种字节序的排列方式分别如下:

*

* Big Endian

*

*低地址高地址

* ---------------------------------------------------- & gt;

*地址编号

* | 0 1 2 3 | | | |

* | 01 02 03 04 | | | |

*

* Little Endian

*

*低地址高地址

* ---------------------------------------------------- & gt;

*地址编号

* | 0 1 2 3 | | | |

* | 04 03 02 01 | | | |

*

* java则统一使用大模式

* C中的unsigned short对应着java中的焦两个字节,无符号

* C的无符号int,短,字节数组java字节,相应转换成的长、短焦,

*

作者snowolf * @

* @版本1

*自1起

* /

公共cioutil抽象类{

public static final String charset =“UTF-8”;

/ * *

*从输入流中读布尔

*

* @param是

*归

* @抛出IOException

* /

公共静态布尔readboolean(输入流是)throws IOException {

readboolean()回报;

}

/ * *

*从流中读定长度字节数组

*

* @param是

* @param的

*归

* @抛出IOException

* /

公共静态字节[] readbytes(DataInputStream,int i)

抛出IOException {

字节[数据] =新字节[ i ];

是readfully(数据);

返回数据;

}

/ * *

*从输入流中读字符

*

* @param是

*归

* @抛出IOException

* /

public static char readChar(输入流是)throws IOException {

返回(char)readshort(是);

}

/ * *

*从输入流中读双精度

*

* @param是

*归

* @抛出IOException

* /

public static double readdouble (datainputstream throws ioexception (is)

in double.longbitstodouble (readlong (is).

}

/ * *

* 从输入流中读单精度

*

* @ param is

* @ return

* * * * * * @ throws ioexception

* /

public static float readfloat (datainputstream throws ioexception (is)

in float.intbitstofloat (readint (is).

}

/ * *

* 从流中读整型

*

* @ param is

* @ return

* * * * * * @ throws ioexception

* /

public static int readint (datainputstream throws ioexception (is)

in integer.reversebytes (is.readint ());

}

/ * *

* 从流中读长整型

*

* @ param is

* @ return

* * * * * * @ throws ioexception

* /

public static long readlong (datainputstream throws ioexception (is)

in long.reversebytes (is.readlong ());

}

/ * *

* 从流中读短整型

*

* @ param is

* @ return

* * * * * * @ throws ioexceptio

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值