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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 9679|回復: 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);
  }
}


回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精品一区2区 | 免费看黄色国产 | 国产精品美女久久久免费 | 国产传媒毛片精品视频第一次 | 视频在线h| 免费在线观看一区二区三区 | 成人精品久久 | 中文字幕免费 | 黄色激情毛片 | 日韩欧美国产成人一区二区 | 中文字幕国产视频 | 亚洲福利在线观看 | 一级在线毛片 | 亚洲欧美国产精品久久 | 久久久久久看片 | 1级黄色大片 | 欧美三级不卡 | 成人综合伊人 | 日韩精品免费在线观看 | 一级aaaa毛片 | 91精品国产高清一区二区三区 | 欧美成人性生活 | 国产精品久久亚洲 | 99精品一区二区 | 91精品久久久久久久久 | 男女免费在线观看视频 | 久久中文视频 | 日韩中文字幕一区 | 久在线 | 日本视频在线播放 | 伊人99| 欧美综合一区二区三区 | www.99热这里只有精品 | 国产精品久久久久久久久久久久久 | 午夜在线小视频 | 国产精品久久99 | 黑人巨大精品欧美一区二区免费 | 久久久久亚洲精品 | 欧美精品一区久久 | 另类视频区 | 国产一区久久 |