C\#자바 에서 바 이 너 리 숫자 를 읽 을 때의 차이 점
1697 단어 JAVA
JAVA 코드 는 다음 과 같 습 니 다.
static int readCsharpInt(InputStream in) throws IOException
{
byte[] bytes = new byte[4];
bytes[3] =(byte)in.read();
bytes[2] =(byte)in.read();
bytes[1] =(byte)in.read();
bytes[0] =(byte)in.read();
ByteBuffer buffer = ByteBuffer.wrap(bytes);
return buffer.getInt();
}
static short readCsharpShort(InputStream in) throws IOException
{
byte[] bytes = new byte[2];
bytes[1] =(byte)in.read();
bytes[0] =(byte)in.read();
ByteBuffer buffer = ByteBuffer.wrap(bytes);
return buffer.getShort();
}
static int readJavaInt(InputStream in) throws IOException
{
byte[] bytes = new byte[4];
bytes[0] =(byte)in.read();
bytes[1] =(byte)in.read();
bytes[2] =(byte)in.read();
bytes[3] =(byte)in.read();
ByteBuffer buffer = ByteBuffer.wrap(bytes);
return buffer.getInt();
}
static short readJavaShort(InputStream in) throws IOException { byte[] bytes = new byte[2]; bytes[0] =(byte)in.read(); bytes[1] =(byte)in.read(); ByteBuffer buffer = ByteBuffer.wrap(bytes); return buffer.getShort(); }
이렇게 하면 정확 하 다.위 에서 읽 은 바이트 의 배열 순서 가 완전히 반대 되 는 것 을 볼 수 있다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JAVA 객체 작성 및 제거 방법정적 공장 방법 정적 공장 방법의 장점 를 반환할 수 있습니다. 정적 공장 방법의 단점 류 공유되거나 보호된 구조기를 포함하지 않으면 이불류화할 수 없음 여러 개의 구조기 파라미터를 만났을 때 구축기를 고려해야 한다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.