⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ascii2bcd.java

📁 ASCII码与BCD码压缩变换程序代码
💻 JAVA
字号:
import java.io.FileOutputStream;
import java.lang.Exception;

public class ascii2bcd
{
private static byte[] bcd =new byte[2];

private static byte aasc_to_bcd(byte asc)
{
	byte bcd;

	if ((asc >='0') &&(asc <='9'))
    	bcd =(byte)(asc -'0');
	else if ((asc >='A') &&(asc <='F'))
    	bcd =(byte)(asc -'A' +10);
	else if ((asc >='a') &&(asc <='f'))
    	bcd =(byte)(asc -'a' +10);
	else
    	bcd =(byte)(asc -48);
	return bcd;
}


private static void ASCII_To_BCD(byte[] ascii, int asc_len)
{
	int j =0;
	for (int i =0; i <(asc_len +1) /2; i ++)
    {
    	bcd[i] =aasc_to_bcd(ascii[j ++]);
    	bcd[i] =(byte)(((j >=asc_len) ?0x00 :aasc_to_bcd(ascii[j ++])) +(bcd[i] <<4));
    }
}

public static void main(String[] args)
{
	byte[] ascii ={'0', '8', '2', '6'};
	ASCII_To_BCD(ascii, 4);	
	try
	{
		FileOutputStream outFile =new FileOutputStream("c:\\aa.txt");
		outFile.write(bcd, 0, 2);
		outFile.close();
	}
	catch(Exception e)
	{
	}
	
	//String stringOut ="Ox"+Integer.toHexString(bcd[0]);
	//System.out.println(stringOut);
	//stringOut ="Ox"+Integer.toHexString(bcd[1]);
	//System.out.println(stringOut);
}
}//end of class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -