Exercise 2-8.

来源:互联网 发布:数据库设计思路与原则 编辑:程序博客网 时间:2024/06/05 00:29
Exercise 2-8.Write a function  rightrot(x,n) that returns the value of the integer  x rotated

to the right b y npositions.


int unsignedLength(){unsigned x = (unsigned)~0;int i = 0;while (x != 0){x = x >> 1;i++;}return i;}unsigned rightrot(unsigned x, int n){int l = unsignedLength();int a, b, c;a = (~0) >> (l - n) | x;b = x >> n;c = a << (l - n);return b | c;}


0 0