【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
相关文档:
Delphi 与 C/C++ 数据类型对照表
Delphi数据类型C/C++
ShorInt
8位有符号整数
char
Byte
8位无符号整数
BYTE,unsigned short
SmallInt
16位有符号整数
short
Word
16位无符号整数
unsigned short
Integer,LongInt
32位有符号整数
int,long
Cardinal,LongWord/DWORD
32位无符号整数
unsigned long
Int6 ......
由于Boost Python跟不上Python版本更新,如下方法调用可能产生TypeError: 'NoneType' object does not support item assignment异常。
Boost Python文档中例子可能产生异常。
Py_Initialize();
object main_module = import("__main__");
object main_dict = main_module.attr("__dict__");
try{
object ......
通用函数库在头文件stdlib.h中声明,比较庞大,主要分为以下几大类:存储分配、随机数生成、数字转换与整型运算、程序退出与环境通信、搜索与排序、多字节与宽字符的转换。由于汲及到存储分配、环境通信等,因此它们的大多数也依赖于操作系统。glibc中,通用函数库的核心实现在stdlib和malloc两个目录下 ......
编者按:非常基本关于C语言的问题,一个信息类(计算机,资讯工程,电子工程, 通信
工程)专业的本科毕业生应该达到的水平。题目不难,全部都能快速地答完,当然也需要
一定的知识储备。
对于大多数人,我们预期你可能答错 1) 4) 15)题,所以答错3道以内的,我们认为
你很棒
答错5道题以 ......
计算线程执行某项任务消耗的时间时,许多开发人员会调用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 ......