久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 9543|回復: 0
打印 上一主題 下一主題
收起左側

二進制轉BCD碼快速算法 bin to bcd fast code.

[復制鏈接]
跳轉到指定樓層
樓主
ID:71407 發表于 2014-12-31 01:01 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
                                                                                                24位BIN轉BCD碼:
//--------------start of file---------------- -
-
extern void bin2bcd(unsigned char *output, unsigned long input); -
-
void bin2bcd(unsigned char *output, unsigned long input) -
{ -
*output = 0; -
if (input >= 4000000000) { *output += 0x40; input -= 4000000000; } -
if (input >= 2000000000) { *output += 0x20; input -= 2000000000; } -
if (input >= 1000000000) { *output += 0x10; input -= 1000000000; } -
if (input >= 800000000) { *output += 0x08; input -= 800000000; } -
if (input >= 400000000) { *output += 0x04; input -= 400000000; } -
if (input >= 200000000) { *output += 0x02; input -= 200000000; } -
if (input >= 100000000) { *output += 0x01; input -= 100000000; } -
output++; -
-
*output = 0; -
if (input >= 80000000) { *output += 0x80; input -= 80000000; } -
if (input >= 40000000) { *output += 0x40; input -= 40000000; } -
if (input >= 20000000) { *output += 0x20; input -= 20000000; } -
if (input >= 10000000) { *output += 0x10; input -= 10000000; } -
if (input >= 8000000) { *output += 0x08; input -= 8000000; } -
if (input >= 4000000) { *output += 0x04; input -= 4000000; } -
if (input >= 2000000) { *output += 0x02; input -= 2000000; } -
if (input >= 1000000) { *output += 0x01; input -= 1000000; } -
output++; -
-
*output = 0; -
if (input >= 800000) { *output += 0x80; input -= 800000; } -
if (input >= 400000) { *output += 0x40; input -= 400000; } -
if (input >= 200000) { *output += 0x20; input -= 200000; } -
if (input >= 100000) { *output += 0x10; input -= 100000; } -
if (input >= 80000) { *output += 0x08; input -= 80000; } -
if (input >= 40000) { *output += 0x04; input -= 40000; } -
if (input >= 20000) { *output += 0x02; input -= 20000; } -
if (input >= 10000) { *output += 0x01; input -= 10000; } -
output++; -
-
*output = 0; -
if (input >= 8000) { *output += 0x80; input -= 8000; } -
if (input >= 4000) { *output += 0x40; input -= 4000; } -
if (input >= 2000) { *output += 0x20; input -= 2000; } -
if (input >= 1000) { *output += 0x10; input -= 1000; } -
if (input >= 800) { *output += 0x08; input -= 800; } -
if (input >= 400) { *output += 0x04; input -= 400; } -
if (input >= 200) { *output += 0x02; input -= 200; } -
if (input >= 100) { *output += 0x01; input -= 100; } -
output++; -
-
*output = 0; -
if (input >= 80) { *output += 0x80; input -= 80; } -
if (input >= 40) { *output += 0x40; input -= 40; } -
if (input >= 20) { *output += 0x20; input -= 20; } -
if (input >= 10) { *output += 0x10; input -= 10; } -
*output += (unsigned char)(input & 0x0F); -
} -
-
unsigned char output[5]; -
-
int main(int argc, char* argv[]) -
{ -
-
bin2bcd(output,0xFFFFFFFF); -
bin2bcd(output,3999999999); -
bin2bcd(output,0); -
return 0; -
} -
-
//--------------end of file-----------------


16位BIN轉BCD碼
#include <REG52.H>
#define wufuhao_zifu unsigned char
void calculate(unsigned int value)
{
  wufuhao_zifu tempA;    //變量保存16位的高8位
  wufuhao_zifu tempB;    //變量保存16位的低8位
  wufuhao_zifu temp1;    //變量保存16位數據的個位
  wufuhao_zifu temp2;    //變量保存16位數據的十位
  wufuhao_zifu temp3;    //變量保存16位數據的百位
  wufuhao_zifu temp4;    //變量保存16位數據的千位
  wufuhao_zifu temp5;    //變量保存16位數據的萬位
  tempA=value>>8;
  tempB=value&0x00ff;
  temp1=temp2=temp3=temp4=temp5=0;
  while(((tempA==0x27)&&(tempB>=0x10))||(tempA>0x27))
    {
    if(tempB>=0x10)
    {
    tempB-=0x10;
    tempA-=0x27;
    }
    else
    {
    tempB+=(~0x10)+1;
    tempA-=0x27+1;
    }
    temp5++;
    }
        
  while(((tempA==0x03)&&(tempB>=0xe8))||(tempA>0x03))
    {
    if(tempB>=0xe8)
    {
      tempB-=0xe8;
      tempA-=0x03;        
    }
    else
    {
      tempB+=(~0xe8)+1;
      tempA-=0x03+1;
    }
      temp4++;
    }
  while(((tempA==0)&&(tempB>=0x64))||(tempA>0))
    {
    if(tempB>=0x64)
    {
      tempB-=0x64;
    }
    else
    {
      tempB+=(~0x64)+1;
      tempA-=1;
    }
      temp3++;
    }
        
  while(tempB>=0x0a)
    {
    tempB-=0x0a;
    temp2++;
    }
        
  while(tempB>=0x01)
    {
    tempB-=0x01;
    temp1++;
    }
}
void main()
{
  while(1)
    {
calculate(65535);
}
}
---------------------------------------------------------------------------------------------------------------
非常快速的16位BIN轉BCD程序
#include <reg51.h>
unsigned char dig[5];
void bin2bcd(unsigned int x)
{
  unsigned char i,j,k;
  k = x;
  x >>= 2;
  i = x >> 8;
  j = (i + i + i) << 1;
  if (i > 41) {i++;j+=6;}
  j += x;
  if ((unsigned char)x > j ) {i++;j+=6;}
  if (j > 249) {i++;j+=6;}
  dig[0] = i / 10;                      //10000
  dig[1] = B;                           //1000
  dig[2] = j / 25;                      //100
  dig[3] = (B<<2 | k&3) / 10;           //10
  dig[4] = B;                           //1
}
void main()
{
while(1)
  {
  bin2bcd(32768);
  }
}


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 精品欧美一区二区三区久久久 | 国产精品亚洲一区 | 热久久久久 | 久久国产精品99久久久久 | 欧美一区二区另类 | 日本综合在线观看 | 日韩精品无码一区二区三区 | 亚洲97 | 欧美日韩综合视频 | 综合天天久久 | 亚洲精品久久久一区二区三区 | 亚洲精品无人区 | 国产91在线播放 | 国产精品3区 | 一区二区在线不卡 | 美女爽到呻吟久久久久 | 日韩电影一区 | 精久久 | 中文一区二区 | 在线中文字幕av | 羞羞视频网站免费观看 | 免费成人高清在线视频 | 午夜欧美一区二区三区在线播放 | 国产精品亚洲视频 | 国产精品视频中文字幕 | 亚洲午夜电影 | 中文字幕在线一区 | 日韩精品一区二区三区 | 亚洲综合国产 | av天空| 在线国产一区 | 日韩综合在线 | 天天操天天摸天天爽 | 欧美一级淫片免费视频黄 | 人干人人| 天天干视频网 | 国内精品久久久久久 | 国产目拍亚洲精品99久久精品 | 国产精品v | 国产日韩精品一区 | 韩日一区二区 |