c programming language learn notes 9
2006-09-23 20:50
375 查看
终是把位操作给看了的说
有两点新发现,
位操作是对于intger的,就是int,char,unsigned,long类
转化符的操作数只能为,无符号
^_^
另外,一道习题
觉得谭爷爷那本书里面的比老外的要好些,也容易理解
Write a function
Greg's Cat 0 solution
有两点新发现,
位操作是对于intger的,就是int,char,unsigned,long类
转化符的操作数只能为,无符号
^_^
另外,一道习题
觉得谭爷爷那本书里面的比老外的要好些,也容易理解
Write a function
rightrot(x,n)that returns the value of the integer
xrotated to the right by
nbit positions.
Greg's Cat 0 solution
unsigned rightrot(unsigned x, unsigned n) { while (n > 0) { if ((x & 1) == 1) x = (x >> 1) | ~(~0U >> 1); else x = (x >> 1); n--; } return x; }
下面讲讲谭爷爷的方法,
1.b=a<<(16-n);//将a的右端n位先放到b的高n位中
2.c=a>>n;//将a右移n位,其左面高位n位补0
3.c=c|b;//按位或运算
相关文章推荐
- c programming language learn notes 7
- c programming language learn notes 10
- c programming language learn notes 8
- c programming language learn notes 11
- c programming language learn notes 6
- Notes to the Reader(Chapter 1 of The C++ Programming Language)
- The C# Programming Language Notes II
- c programe language learn notes 2
- c programe language learn notes 3
- The Java Programming Language Notes
- The C# Programming Language Notes
- What Programming Language to Learn (Next)
- c programming language learn note 4
- The Ruby Programming Language Notes
- What is the Best Programming Language to Learn in 2014?
- K&R the C programming language——study notes
- The Python Programming Language Notes
- How to Learn a Programming Language
- c programming language learn 5
- Home at Last, or, The Last Programming Language I Will Ever Learn: LISP (Clojure)