uint

Arithmetic operation resulted in an overflow in unsafe C#

纵然是瞬间 提交于 2019-12-04 10:26:29
Background We've been using some code copied verbatim from Joe Duffy's "Concurrent Programming on Windows" (page 149) in production for over a year. The code (below) is used in our Asp.Net web application to probe if there's enough stack space. Our site allows users to script out their own web pages and control logic in a simple proprietry scripting language - it's possible for a user to script something nasty and cause a stackoverflow exception, so we use Duffy's code example to stop execution of the errant script before the uncatchable StackOverflow exception takes down the whole IIS AppPool

Swift: How to convert String to UInt?

血红的双手。 提交于 2019-12-03 12:39:39
According to Swift - Converting String to Int , there's a String method toInt() . But, there's no toUInt() method. So, how to convert a String to a Uint ? Update for Swift 2/Xcode 7: As of Swift 2, all integer types have a (failable) constructor init?(_ text: String, radix: Int = default) which replaces the toInt() method of String , so no custom code is needed anymore for this task: print(UInt("1234")) // Optional(1234) // This is UInt.max on a 64-bit platform: print(UInt("18446744073709551615")) // Optional(18446744073709551615) print(UInt("18446744073709551616")) // nil (overflow) print

unsigned int (c++) vs uint (c#)

我的未来我决定 提交于 2019-12-03 10:29:24
问题 Following is the c# code: static void Main(string[] args) { uint y = 12; int x = -2; if (x > y) Console.WriteLine("x is greater"); else Console.WriteLine("y is greater"); } and this is c++ code: int _tmain(int argc, _TCHAR* argv[]) { unsigned int y = 12; int x = -2; if(x>y) printf("x is greater"); else printf("y is greater"); return 0; } Both are giving different result. Am I missing something basic? Any idea? 回答1: C++ and C# are different languages. They have different rules for handling

Printing a void* variable in C

南笙酒味 提交于 2019-12-03 08:44:31
问题 Hi all I want to do a debug with printf. But I don't know how to print the "out" variable. Before the return, I want to print this value, but its type is void* . int hexstr2raw(char *in, void *out) { char c; uint32_t i = 0; uint8_t *b = (uint8_t*) out; while ((c = in[i]) != '\0') { uint8_t v; if (c >= '0' && c <= '9') { v = c - '0'; } else if (c >= 'A' && c <= 'F') { v = 10 + c - 'A'; } else if (c >= 'a' || c <= 'f') { v = 10 + c - 'a'; } else { return -1; } if (i%2 == 0) { b[i/2] = (v << 4);

unsigned int (c++) vs uint (c#)

北慕城南 提交于 2019-12-03 02:02:36
Following is the c# code: static void Main(string[] args) { uint y = 12; int x = -2; if (x > y) Console.WriteLine("x is greater"); else Console.WriteLine("y is greater"); } and this is c++ code: int _tmain(int argc, _TCHAR* argv[]) { unsigned int y = 12; int x = -2; if(x>y) printf("x is greater"); else printf("y is greater"); return 0; } Both are giving different result. Am I missing something basic? Any idea? C++ and C# are different languages. They have different rules for handling type promotion in the event of comparisons. In C++ and C, they're usually compared as if they were both

How to convert char to hex stored in uint8_t form?

对着背影说爱祢 提交于 2019-12-02 04:40:33
Suppose I have these variables, const uint8_t ndef_default_msg[33] = { 0xd1, 0x02, 0x1c, 0x53, 0x70, 0x91, 0x01, 0x09, 0x54, 0x02, 0x65, 0x6e, 0x4c, 0x69, 0x62, 0x6e, 0x66, 0x63, 0x51, 0x01, 0x0b, 0x55, 0x03, 0x6c, 0x69, 0x62, 0x6e, 0x66, 0x63, 0x2e, 0x6f, 0x72, 0x67 }; uint8_t *ndef_msg; char *ndef_input = NULL; How can I convert ndef_input (which is just a plain text, like "hello") to hex and save into ndef_msg ? As you can see ndef_default_msg is in hex form. Data inside ndef_msg should be something like that as well. A bit of background, in the original program ( source code ), the program

Get Unix timestamp with C++

守給你的承諾、 提交于 2019-11-28 20:02:01
How do I get a uint unix timestamp in C++? I've googled a bit and it seems that most methods are looking for more convoluted ways to represent time. Can't I just get it as a uint ? Tony Delroy time() is the simplest function - seconds since Epoch. Linux manpage here . The cppreference page linked above gives this example : #include <ctime> #include <iostream> int main() { std::time_t result = std::time(nullptr); std::cout << std::asctime(std::localtime(&result)) << result << " seconds since the Epoch\n"; } #include<iostream> #include<ctime> int main() { std::time_t t = std::time(0); // t is an

Get Unix timestamp with C++

谁都会走 提交于 2019-11-27 12:53:45
问题 How do I get a uint unix timestamp in C++? I've googled a bit and it seems that most methods are looking for more convoluted ways to represent time. Can't I just get it as a uint ? 回答1: time() is the simplest function - seconds since Epoch. Linux manpage here. The cppreference page linked above gives this example: #include <ctime> #include <iostream> int main() { std::time_t result = std::time(nullptr); std::cout << std::asctime(std::localtime(&result)) << result << " seconds since the Epoch

Why is Array.Length an int, and not an uint [duplicate]

折月煮酒 提交于 2019-11-26 05:59:01
问题 This question already has answers here : Why does .NET use int instead of uint in certain classes? (8 answers) Closed 6 years ago . Why is Array.Length an int, and not a uint . This bothers me (just a bit) because a length value can never be negative. This also forced me to use an int for a length-property on my own class, because when you specify an int-value, this needs to be cast explicitly... So the ultimate question is: is there any use for an unsigned int ( uint )? Even Microsoft seems