剑指offer
来源:互联网 发布:ae软件 编辑:程序博客网 时间:2024/05/13 23:53
package Chapter2;/** * 面试题10:二进制中1的个数 *输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。 * *内存中 的那个数(补码)1的个数 */public class _10_binary {public static void main(String[] args) {_10_function f = new _10_function();// 1000 0000, 0111 1111, 1000 0000 -128// 补码的补码 是 源码int count = f.counter(-0x7ffffffe);// -2,负数用补码表示 //int count = f.counter(127);System.out.println(count);}}class _10_function {int counter(int num) {int count = 0;int one = 1;while(one != 0) {// 0 与,1或,1与 1 筛选if((num & one) != 0) count ++;one <<= 1;}return count;}}
阅读全文
0 0
- 剑指OFFER
- 剑指offer
- 剑指Offer
- 剑指offer
- 剑指Offer
- 剑指offer
- 剑指offer
- 剑指offer
- 剑指Offer
- 剑指offer
- 剑指offer
- 剑指Offer
- 剑指offer
- 剑指offer
- 《剑指offer》
- 剑指Offer
- 剑指offer
- 剑指offer
- [原创]新作品发布:asp来设置windows自带的防火墙
- CDSN 博客转载
- 三米的距离买32寸好还是37寸好?
- 拼音字典(Maxthon插件)
- 旅行必打卡的网红街拍景点-首尔Common Ground集装箱集市
- 剑指offer
- 男子称扶摔倒老太反被告 被判赔4万(图)
- 测试一下邮件写博客
- Modem常用简称
- 越有钱就越小气吗?还是店大欺客?
- 以前天天来,现在天天不来~~
- linux学习中遇到的bug
- git commit
- 电子商务系统+java+web+完整项目+包含源码和数据库Java实用源码