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

查看所有标签

Programming Concurrency on the JVM

Programming Concurrency on the JVM

Venkat Subramaniam / The Pragmatic Bookshelf / 2011-6-1 / USD 35.00

Concurrency on the Java platform has evolved, from the synchronization model of JDK to software transactional memory (STM) and actor-based concurrency. This book is the first to show you all these con......一起来看看 《Programming Concurrency on the JVM》 这本书的介绍吧!

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

在线图片转Base64编码工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试