C Primer Plus(第六版)15.9 编程练习 第5题

//

// main.c

// 15.9-5

//

// Created by cjm on 2024/2/5.

//

#include <stdio.h>

#include <limits.h>

char * itobs(int n, char * ps);

unsigned int rotate(unsigned int x,int i);

int main()

{

unsigned int x=2999999999;

printf("%u\n",rotate(x,3));//注意这里的打印格式

return 0;

}

unsigned int rotate(unsigned int x,int i)

{

unsigned int len;

len = sizeof (unsigned int)*CHAR_BIT;

char strlen+1;

while(i!=0)

{

printf("旋转前 x=%s\n",itobs(x, str));

printf(" x<<1=%s\n",itobs(x<<1, str));

printf("x>>(len-1)=%s\n",itobs(x>>(len-1), str));

x=x<<1|((x>>(len-1))&1);

printf("旋转后 x=%s\n",itobs(x, str));

i--;

}

return x;

}

char * itobs(int n, char * ps)

{

int i;

const static int size = CHAR_BIT * sizeof (int);

for (i = size - 1; i >= 0; i--, n >>= 1)

{

psi = (01 & n) + '0';

}

pssize = '\0';

return ps;

}

相关推荐
LDR0062 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术2 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园2 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob2 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享2 天前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm
Luminous.2 天前
C语言--day30
c语言·开发语言
玖玥拾2 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
何以解忧,唯有..2 天前
Go语言循环语句详解:for、range与循环控制
开发语言·算法·golang
謓泽2 天前
C语言不是语法,是通往机器的地图。
c语言·开发语言
云水一下2 天前
从零开始学 PHP 系列(一):PHP 的前世今生与开发环境搭建
开发语言·php