大约有 40,000 项符合查询结果(耗时:0.0277秒) [XML]

https://stackoverflow.com/ques... 

C++ convert hex string to signed integer

...> std::hex >> out.value; return in; } }; Used like uint32_t value = boost::lexical_cast<HexTo<uint32_t> >("0x2a"); That way you don't need one impl per int type. share | ...
https://stackoverflow.com/ques... 

How do I detect unsigned integer multiply overflow?

...the largest operand's highest one-bit. For example: bool addition_is_safe(uint32_t a, uint32_t b) { size_t a_bits=highestOneBitPosition(a), b_bits=highestOneBitPosition(b); return (a_bits<32 && b_bits<32); } For multiplication, any two operands will result in (at most) the s...
https://stackoverflow.com/ques... 

Quickly find whether a value is present in a C array?

... the last entry in the array, then return true Return false bool check(uint32_t theArray[], uint32_t compareVal) { uint32_t i; uint32_t x = theArray[SIZE-1]; if (x == compareVal) return true; theArray[SIZE-1] = compareVal; for (i = 0; theArray[i] != compareVal; i++); ...
https://stackoverflow.com/ques... 

Why can't C compilers rearrange struct members to eliminate alignment padding? [duplicate]

... data directly): struct __attribute__((__packed__)) LocalFileHeader { uint32_t signature; uint16_t minVersion, flag, method, modTime, modDate; uint32_t crc32, compressedSize, uncompressedSize; uint16_t nameLength, extraLength; }; The packed attribute prevents the compiler from ali...
https://stackoverflow.com/ques... 

How to create NS_OPTIONS-style bitmask enumerations in Swift?

...like this: struct MyOptions : RawOptionSetType { typealias RawValue = UInt private var value: UInt = 0 init(_ value: UInt) { self.value = value } init(rawValue value: UInt) { self.value = value } init(nilLiteral: ()) { self.value = 0 } static var allZeros: MyOptions { return...
https://stackoverflow.com/ques... 

Kill child process when parent process is killed

... public Int64 PerJobUserTimeLimit; public Int16 LimitFlags; public UInt32 MinimumWorkingSetSize; public UInt32 MaximumWorkingSetSize; public Int16 ActiveProcessLimit; public Int64 Affinity; public Int16 PriorityClass; public Int16 SchedulingClass; } [StructLayout(LayoutK...
https://stackoverflow.com/ques... 

Random number generation in C++11: how to generate, how does it work? [closed]

...t19937 MyRNG; // the Mersenne Twister with a popular choice of parameters uint32_t seed_val; // populate somehow MyRNG rng; // e.g. keep one global instance (per thread) void initialize() { rng.seed(seed_val); } Now we can create distributions: std::uniform_int_di...
https://stackoverflow.com/ques... 

Real world use cases of bitwise operators [closed]

...egister to make some piece of hardware do what you want it to: volatile uint32_t *register = (volatile uint32_t *)0x87000000; uint32_t value; uint32_t set_bit = 0x00010000; uint32_t clear_bit = 0x00001000; value = *register; // get current value from the r...
https://stackoverflow.com/ques... 

How to write a large buffer into a binary file in C++, fast?

...thm> #include <iostream> #include <cassert> std::vector<uint64_t> GenerateData(std::size_t bytes) { assert(bytes % sizeof(uint64_t) == 0); std::vector<uint64_t> data(bytes / sizeof(uint64_t)); std::iota(data.begin(), data.end(), 0); std::shuffle(data.begin...
https://stackoverflow.com/ques... 

hash function for string

...enkins One At A Time Hash. It also quotes improved versions of this hash. uint32_t jenkins_one_at_a_time_hash(char *key, size_t len) { uint32_t hash, i; for(hash = i = 0; i < len; ++i) { hash += key[i]; hash += (hash << 10); hash ^= (hash >> 6); ...