Coder Jozu

I believe --- 这里坚持原创,拒绝转贴

  VC知识库BLOG :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 登录 ::
  13 随笔 :: 4 文章 :: 87 评论 :: 1 Trackbacks
<2005年3月>
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789

留言簿(4)

随笔分类

随笔档案

文章分类

文章档案

东接西链

搜索

最新评论

阅读排行榜

评论排行榜

2005年3月9日 #

// Bits.cpp : Calculate numbers of bits on a long number.
// Coder Jozu

#include "stdafx.h"

int main(int argc, char* argv[])
{
 long x;
 int num;
 char buff[128];

 
 while(1)
 {
  printf("enter a hex value:");
  gets(buff);
  if(buff[0] == 'q' || buff[0] == 'Q')
   break;

  if(!sscanf(buff, "%X", &x))
  {
   printf("Invalid number.\n");
   continue;
  }
  
  __asm
  {
   push esi
   push eax

   mov eax, x
   mov ecx, 32
   xor esi, esi
next:
   shr eax, 1
   jc  AddOne
   dec ecx
   jcxz end
   jmp next
AddOne:
   inc esi
   jmp next
end:
   mov num, esi
   pop eax
   pop esi
  }
  
  printf("number of %X has %d bits.\n", x, num);
 }
 return 0;
}

 

发表于 2005-03-09 11:27 Coder Jozu 阅读(2787) | 评论 (2)编辑 收藏