随笔分类 -  Bit Operation

摘要:Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). Note: Note that in some 阅读全文
posted @ 2020-12-01 12:30 北叶青藤 阅读(101) 评论(0) 推荐(0)
摘要:byte swap一个 32位数 0x12345678 --> 0x78563412先是用了俩高低位mask 两两交换,不满意。然后用了一个mask,每次取一个byte,移位异或ans。一共执行四次,还是不满意。提示说用两步,能不能先交换 LSB 和 MSB,写了一下,但还是想不出怎么写。。。正解: 阅读全文
posted @ 2020-02-07 03:49 北叶青藤 阅读(765) 评论(0) 推荐(0)
摘要:Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assum 阅读全文
posted @ 2016-08-04 01:03 北叶青藤 阅读(191) 评论(0) 推荐(0)
摘要:Given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e g , M becomes a s 阅读全文
posted @ 2016-07-20 04:46 北叶青藤 阅读(227) 评论(0) 推荐(0)
摘要:Write a function that add two numbers A and B. You should not use + or any arithmetic operators. 分析: 典型的Bit Operation. 阅读全文
posted @ 2016-07-06 02:21 北叶青藤 阅读(192) 评论(0) 推荐(0)
摘要:Single Number Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Example Given [1,2,2,1,3,4,3], return 4 分析: 利用bit operator ^ 的特点即 阅读全文
posted @ 2016-07-04 11:27 北叶青藤 阅读(165) 评论(0) 推荐(0)