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;

}

相关推荐
方也_arkling8 小时前
【Java-Day08】static / final / 枚举
java·开发语言
风吹夏回9 小时前
Python 全局异常处理:从“满屏 try-except”到优雅兜底
开发语言·python
Chengbei119 小时前
一站式源码安全检测工具、云安全 / APP / 小程序源码敏感信息递归多层目录扫描AK、JWT、手机号、身份证等敏感信息
java·开发语言·安全·web安全·网络安全·系统安全·安全架构
llz_1129 小时前
web-第一次课后作业
java·开发语言·idea
kkeeper~9 小时前
0基础C语言积跬步之数据在内存中的存储
c语言·数据结构·算法
小熊Coding9 小时前
Python爬取当当网二手图书项目实战!
开发语言·爬虫·python·beautifulsoup·requests·二手图书
秋99 小时前
Java项目运行5天左右自动宕机:系统性定位与解决方案
java·开发语言·python
xiaoshuaishuai89 小时前
C# 内存管理与资源泄漏
开发语言·c#
lsx20240610 小时前
SVN 检出操作
开发语言
basketball61611 小时前
C++ NULL 和 nullptr 区别 以及 nullptr 的核心实现
java·开发语言·c++