【C】移位操作 处理乘法
今天在douban上面看到了一个帖子,里面关于乘法问题大家讨论了一下
http://www.douban.com/group/topic/8384097/
看到移位做乘法也不是第一次了,但是很诧异真的会在用,自己水平还就差了那么一点点,无可否认,我们处理器的ALU做移位是相当高效的。
这里记录一下里面的一个移位乘法例子。
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ()
{
unsigned long int sum=0;
unsigned int a=0x49d;
unsigned int b=0xd;
unsigned int c=0x1;
unsigned int test;
printf("%d * %d", a, b);
for(c = 1; c; c<<=1, a<<=1)
if (test = b&c) sum += a;
printf("= %d.\n",sum);
system("pause");
return 0;
}
实现了1181 * 13
相关文档:
这篇文章是使用SQLite C/C++接口的一个概要介绍和入门指南。
由于早期的SQLite只支持5个C/C++接口,因而非常容易学习和使用,但是随着SQLite功能的增强,新的C/C++接口不断的增加进来,到现在有超过150个不同的API接口。这往往使初学者望而却步。幸运的是,大多数SQLite中的C/C++接口是专用的,因而很少被使用到。尽管有这 ......
Java语言本身具有跨平台性,如果通过Java调用DLL的技术方便易用,使用Java开发前台界面可以更快速,也能带来跨平台性。
Java调用C/C++写好的DLL库时,由于基本数据类型不同、使用字节序列可能有差异,所以在参数传递过程中容易出现问题,DLL中可能需要做相应的转换。
使用Java调用DLL动态链接库的方案通常有三种:JNI, Ja ......
/加了下面两个头文件,是为了在Win32工程中使用MFC的特性!
#include <afx.h>
#include <afxwin.h>
#include "stdio.h"
#include "conio.h"
////加了下面两句,是为了能够用string(basic_string类型)
#include <string>
using namespace std;
int main(int argc, char* argv[ ......
计算线程执行某项任务消耗的时间时,许多开发人员会调用GetTickCount/GetTickCount64编写如下的代码:
// Get the current time (start time)
ULONGLONG qwStartTime = GetTickCount64();
// Perform complex algorithm here
// Subtract start time from current time to get duration
ULONGLONG dwElapsedTime = Get ......