C 练习实例 54

C 语言教程 · 2019-02-22 07:26:38

题目:取一个整数 a 从右端开始的 4~7 位。

程序分析:可以这样考虑:

(1)先使 a 右移 4 位。

(2)设置一个低 4 位全为 1,其余全为 0 的数,可用~(~0<<4)

(3)将上面二者进行 & 运算。

实例

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. // #include <stdio.h> int main() { unsigned a,b,c,d; printf("请输入整数:\n"); scanf("%o",&a); b=a>>4; c=~(~0<<4); d=b&c; printf("%o\n%o\n",a,d); return 0; }

以上实例输出结果为:

请输入整数:
36
36
1

点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html

查看所有标签

Operating Systems

Operating Systems

Remzi Arpaci-Dusseau、Andrea Arpaci-Dusseau / Arpaci-Dusseau Books / 2012-8-19 / USD 21.00

A book about modern operating systems. Topics are broken down into three major conceptual pieces: Virtualization, Concurrency, and Persistence. Includes all major components of modern systems includin......一起来看看 《Operating Systems》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具