易截截图软件、单文件、免安装、纯绿色、仅160KB

C 学习笔记: 移位操作练习。

#include <stdio.h>
unsigned int reverse_bits(unsigned int value)
{
    unsigned int answer;
    unsigned int i;
    answer = 0;
   
    for(i=1;i!=0;i<<=1){ //此循环可以忽略机器的差异。64位和32位皆可用,增强此代码的可移植性
        answer <<=1;
        if(value & 1)
            answer |= 1;
        value >>=1;
    }
    return answer;
}
int main(void)
{
    unsigned int get_answer=reverse_bits(13);
    int i=31;
    char t;
    while(i)
    {
        t ='0'+ ((get_answer >> i) & 1);
        printf("%c",t);
        i--;
    }
}
<<C和指针>> 第5章练习题。
Linux 2.6 kernel中的set_bit操作:
需要考虑机器是32位还是64位的计算机。
static inline void set_bit(int nr, volatile unsigned long *addr)
{
    int *a = (int *)addr;
    int mask;
    //unsigned long flags;
    a += nr >> 5; 
    mask = 1 << (nr & 0x1f);
    //local_irq_save_hw(flags);
    *a |= mask;
    //local_irq_restore_hw(flags);
}


相关文档:

C/C++代码检视要点


版权申明:以下内容属于作者正在写作的《软件测试实践》一书的内容,未经许可不得用于任何正式出版物中,如果转载请注明出处。
作者:周伟明
代码检视要点
代码检视技能属于开发人员的基本功,能够很大程度地反应出开发人员的能力水平,前面4.4.1节已经讲过提高评审检视的方法。下面以实际的C/C++语言方面的代码来讲解 ......

Tricky C questions



以下是几个棘手的
C 问题, 很难做, 看看自己会做几个?
How do you write a program which produces its own source code as its output?
How can I find the day of the week given the date?
Why doesn’t C have nested functions?
What is the most efficient way to count the num ......

C/C++语言实现动态数组

C/C++语言实现动态数组
C数组的小问题
     这里说的动态数组是可以根据需要动态增长占用内存的数组,比如程序初始分配了100个元素,可是运行了一段时间后区区100个空间不能满足了,现在需要400个,怎么办呢;那肯定需要再额外分配300个。
     C语言有realloc()函数来解决空间 ......

C# C/S程序出错:ContextSwitchDeadlock is detected

今天在VS2005调试一个C# C/S程序,当通过RFC与SAP连接时间过长时,出现此错误,在网上找到解决办法。
VS2008上的一个程序,通过Oracle.DataAccess.dll执行drop user
cascade操作,我在sqlplus执行此操作大约需要一分钟左右时间,当我在VS2008中debug启动此程序时,一直接收到
“ContextSwitchDeadlock is detected& ......

C和C++混合编程(__cplusplus 与 external "c" 的使用)

http://www.diybl.com/course/3_program/c++/cppjs/20090403/163906.html
C和C++混合编程(__cplusplus 与 external "c" 的使用)
www.diybl.com 时间:2009-04-03 作者:匿名 编辑:sky 点击: 124 [评论]
第一种理解
比如说你用C++开发了一个DLL库,为了能够让C语言也能够调用你的DLL输出(Export)的函数,你需要用exte ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号