题目地址:https://leetcode.com/problems/number-of-1-bits/解答:public class Solution { // you need to treat n as an unsigned value public int hammingWei...
分类:
其他好文 时间:
2015-04-07 19:14:44
阅读次数:
71
Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming
weight).
For example, the 32-bit integer ’11' has bin...
分类:
其他好文 时间:
2015-04-07 15:43:06
阅读次数:
125
#include
#include
#define CHAR_BIT 8
using namespace std;
template
class bitset
{
typedef unsigned long _Ty;
friend ostream & operator &_R)
{
for(size_t _P=_N;_P>0;)
_O<<(_R.test(--_P)?'1...
分类:
编程语言 时间:
2015-04-07 15:40:31
阅读次数:
285
Reverse Bits
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in b...
分类:
其他好文 时间:
2015-04-07 15:37:12
阅读次数:
95
1 #include 2 #include 3 #include 4 using namespace std; 5 void knuth(int n, int m) 6 { 7 srand((unsigned int)time(NULL)); 8 for (int i = 0; i...
分类:
编程语言 时间:
2015-04-07 11:13:52
阅读次数:
109
1.冒号(:)用法
(1)表示机构内位域的定义(即该变量占几个bit空间)
typedef struct _XXX{
unsigned char a:4;
unsigned char c;
} XXX;
(2)构造函数后面的冒号起分割作用,是类给成员变量赋值的方法,初始化列表,更适用于成员变量的常量const型...
分类:
编程语言 时间:
2015-04-07 09:58:01
阅读次数:
309
1.基本内置类型
C++包含算数类型和空类型。其中算数类型包含字符,整型数,布尔值及浮点数。即char,int,long,bool,float,double等。注意这里有一种称为无符号数的类型unsigned,无符号数恒大于0.需要注意,如果在while中执行:
unsignedint a = 10;
while(a> 0)
{…}
由于a是无符号整型,因此a恒大于0,逻辑判断恒为真...
分类:
编程语言 时间:
2015-04-07 09:57:54
阅读次数:
244
typedef long long ll;
typedef unsigned long long ull;
const int MAGIC = 131;
long long h[N], base[N];
long long MOD = (long long)1e9 + 7;
inline void Hash(char *s) {
int l = strlen(s);
h[0] = 1;
...
分类:
其他好文 时间:
2015-04-06 20:18:59
阅读次数:
128
现象
线上的服务出现coredump,堆栈为:
#0 0x000000000045d145 in GetStackTrace(void**, int, int) ()
#1 0x000000000045ec22 in tcmalloc::PageHeap::GrowHeap(unsigned long) ()
#2 0x000000000045eeb3 in tcmalloc::Page...
分类:
其他好文 时间:
2015-04-06 18:45:36
阅读次数:
394
网上找到的实现md5函数代码,包括一个头文件md5.h和一个源文件md5.c,用下面的测试代码test.c测试通过,各文件依次如下:头文件md5.h: 1 #ifndef MD5_H 2 #define MD5_H 3 4 typedef struct 5 { 6 unsigned in...
分类:
编程语言 时间:
2015-04-06 14:02:37
阅读次数:
258