正序 逆序写 java_C語言版和JAVA版 把一個字節正序(高位在前)轉為逆序(低位在前) 和 逆序轉為正序...
一、C語(yǔ)言版 把一個(gè)字節(jié)正序(高位在前)轉(zhuǎn)為逆序(低位在前) 和?逆序轉(zhuǎn)為正序
// xhrrj.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
//把一個(gè)字節(jié) 高位在前 轉(zhuǎn)為 低位在前
unsigned char Byte_Change(unsigned char ter)
{
unsigned char i=0;
unsigned char tem=0;
for(i=0;i<8;i++)
{
tem=tem<<1; //低位向左移
tem=((ter>>i)&0x01)|tem; //低位的值
}
return tem;
}
//把一個(gè)字節(jié) 低位在前 轉(zhuǎn)為 高位在前
unsigned char Byte_Change2(unsigned char ter)
{
unsigned char i=0;
unsigned char tem=0;
for(i=0;i<8;i++)
{
tem=tem>>1;
tem=((ter<
}
return tem;
}
void main(int argc, char* argv[])
{
unsigned char a=0;
a=Byte_Change(0x22);
printf("%02X\n",a);
a=Byte_Change2(0x44);
printf("%02X\n",a);
}
結(jié)果:
44
22
Press any key to continue
2.JAVA版
public class ByteChange {
static //把一個(gè)字節(jié) 高位在前 轉(zhuǎn)為 低位在前
int Byte_Change(int ter)
{
int i=0;
int tem=0;
for(i=0;i<8;i++)
{
tem=tem<<1; //低位向左移
tem=((ter>>i)&0x01)|tem; //低位的值
}
return tem;
}
//把一個(gè)字節(jié) 低位在前 轉(zhuǎn)為 高位在前
static int Byte_Change2(int ter)
{
int i=0;
int tem=0;
for(i=0;i<8;i++)
{
tem=tem>>1;
tem=((ter<
}
return tem;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=0;
a=Byte_Change(0x22);
System.out.printf("%02X\n",a);
a=Byte_Change2(0x44);
System.out.printf("%02X\n",a);
}
}
總結(jié)
以上是生活随笔為你收集整理的正序 逆序写 java_C語言版和JAVA版 把一個字節正序(高位在前)轉為逆序(低位在前) 和 逆序轉為正序...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java禁止ie后退_Java开发网 -
- 下一篇: java匹配出某单词除外_java正则匹