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

📄 telnum.cpp

📁 BCD码压缩解压缩BCD码用四位二进制数表示一位十进制数
💻 CPP
字号:
// telnum.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include "stdio.h"
typedef unsigned long  DWORD;
typedef unsigned  short  WORD;
typedef struct _tagTELNUM{
	WORD WCountry;
	WORD WRegion;
	WORD WCodeseg;
	WORD WOrdernum;
}TELNUM;
WORD CompressW(char *pn);

void CompressPN(TELNUM *ts,char *pn)//压缩16位电话号码
{
	ts->WCountry=CompressW(pn);
	ts->WRegion=CompressW(pn+4);
	ts->WCodeseg=CompressW(pn+8);
	ts->WOrdernum=CompressW(pn+12);
}
WORD CompressW(char *pn)//压缩4位电话号码部分
{
	WORD cp;
	cp=(pn[2]&0x0f)|(pn[3]<<4);
	cp <<= 8;
	cp |=(WORD)(pn[0]&0x0f)|((pn[1]&0x0f)<<4); 
	return cp;  
}
DWORD CompressDW(char*pn)//压缩8位电话号码部分
{
	DWORD cp;
	cp=CompressW(pn)|(CompressW(pn+4)<<16);
	return cp;
}

char * DecompressPN( char *pn, TELNUM *ts)//解压缩16位号码
{
	
	pn[0]=((ts->WCountry)&0x0f)|0x30;
	pn[1]=(((ts->WCountry)>>4)&0x0f)|0x30;
	pn[2]=(((ts->WCountry)>>8)&0x0f)|0x30;
	pn[3]=(((ts->WCountry)>>12)&0x0f)|0x30;

	pn[4]=((ts->WRegion)&0x0f)|0x30;
	pn[5]=(((ts->WRegion)>>4)&0x0f)|0x30;
	pn[6]=(((ts->WRegion)>>8)&0x0f)|0x30;
	pn[7]=(((ts->WRegion)>>12)&0x0f)|0x30;

	pn[8]=((ts->WCodeseg)&0x0f)|0x30;
	pn[9]=(((ts->WCodeseg)>>4)&0x0f)|0x30;
	pn[10]=(((ts->WCodeseg)>>8)&0x0f)|0x30;
	pn[11]=(((ts->WCodeseg)>>12)&0x0f)|0x30;

	pn[12]=((ts->WOrdernum)&0x0f)|0x30;
	pn[13]=(((ts->WOrdernum)>>4)&0x0f)|0x30;
	pn[14]=(((ts->WOrdernum)>>8)&0x0f)|0x30;
	pn[15]=(((ts->WOrdernum)>>12)&0x0f)|0x30;

	return pn;
}


char *DecompressW(char *pn, WORD w)	 //解压缩4位号码
{	
	for(int i=0;i<4;i++)
	pn[i]=(char)(((w>>4*i)&0x0f)|0x30);
return pn;
}

char *DecompressDW(char *pn, DWORD dw) //解压缩8位号码
{
	for(int i=0;i<8;i++)
	pn[i]=(char)(((dw>>4*i)&0x0f)|0x30);
	return pn;
}


int main(int argc, char* argv[])
{
	char pn[17]="0086002412345678";
    struct _tagTELNUM ts;
	char dpn[16];
	char dpn1[8];
	char dpn2[4];

	CompressPN(&ts,pn);//压缩16位电话号码
	printf("%x,%x,%x,%x\n",ts.WCountry,ts.WRegion,ts.WCodeseg,ts.WOrdernum);
    
	CompressDW(pn+8);//压缩8位号码段
    printf("%x%x\n",ts.WOrdernum,ts.WCodeseg);

	CompressW(pn);//压缩4位国家和地区号
	printf("%x\n",ts.WCountry );
	CompressW(pn+4);
	printf("%x\n",ts.WRegion );

	DecompressPN(dpn,&ts);//解压16位电话号码
	for(int i=0;i<16;i++)
		printf("%c",dpn[i]);
		printf("\n");

    DecompressDW(dpn1, CompressDW(pn+8));//解压8位号码段
	for( i=0;i<8;i++)
		printf("%c",dpn1[i]);
		printf("\n");

	DecompressW(dpn2,CompressW(pn));//解压4位国家和地区号
	for(i=0;i<4;i++)
		printf("%c",dpn2[i]);
		printf("\n");
	DecompressW(dpn2,CompressW(pn+4));
	for(i=0;i<4;i++)
		printf("%c",dpn2[i]);
		printf("\n");

	return 0;
}

⌨️ 快捷键说明

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