unsigned-integer

Java read unsigned int, store, and write it back

喜夏-厌秋 提交于 2019-12-21 21:14:38
问题 I need to read an unsigned int from a quicktime file, and write it back to another quicktime file. Currently I read the unsigned int into a Long but while writing it back I never managed to write the exact number back in 4 bytes as unsigned int. The long has the correct value that I need to write back. (eg 3289763894 or 370500) I am unable to even read the write a number smaller then Integer.MAX_VALUE (eg 2997). I am using the following methods to write the value back public void writeUInt32

64-bit unsigned integers which cannot map onto a double [duplicate]

▼魔方 西西 提交于 2019-12-20 04:19:45
问题 This question already has answers here : Are all integer values perfectly represented as doubles? [duplicate] (5 answers) Closed last year . Are there any 64-bit unsigned integer values which cannot be represented with a double-precision floating-point type? (As a double is also 64-bit wide there must be some.) If so, how can I calculate all of them? (In a not brute force way, maybe?) 回答1: Every integer from 0 to 2^52 inclusive is representable exactly, from 2^52 to 2^53 only every even

What Are Integer Literal Type? And How They Are Stored?

拥有回忆 提交于 2019-12-18 09:22:11
问题 I have just started learning C and a question has bugged me for a while now. If I write int i = -1; unsigned int j = 2; unsigned int k = -2; What is the type of integer literal -1 and 2 and -2 , and how does it get converted to get stored in signed int and unsigned int ? What is meant by signed integer, is that the property of variable or integer literal too? Like -2 is signed integer and 2 is unsigned integer? 回答1: First off, -1 is not an integer constant. It's an expression consisting of a

Why Do We have unsigned and signed int type in C?

人走茶凉 提交于 2019-12-18 08:48:07
问题 I am a beginner in C . I have recently learned about 2's Complement and other ways to represent negative number and why 2's complement was the most appropriate one. What i want to ask is for example, int a = -3; unsigned int b = -3; //This is the interesting Part. Now , for the conversion of int type The standard says: 6.3.1.3 Signed and unsigned integers When a value with integer type is converted to another integer type other than _Bool, if the value can be represented by the new type, it

Weird result after assigning 2^31 to a signed and unsigned 32-bit integer variable

ε祈祈猫儿з 提交于 2019-12-17 20:49:07
问题 As the question title reads, assigning 2^31 to a signed and unsigned 32-bit integer variable gives an unexpected result. Here is the short program (in C++ ), which I made to see what's going on: #include <cstdio> using namespace std; int main() { unsigned long long n = 1<<31; long long n2 = 1<<31; // this works as expected printf("%llu\n",n); printf("%lld\n",n2); printf("size of ULL: %d, size of LL: %d\n", sizeof(unsigned long long), sizeof(long long) ); return 0; } Here's the output: MyPC /

What is a difference between unsigned int and signed int in C?

北城以北 提交于 2019-12-17 17:39:40
问题 Consider these definitions: int x=5; int y=-5; unsigned int z=5; How are they stored in memory? Can anybody explain the bit representation of these in memory? Can int x=5 and int y=-5 have same bit representation in memory? 回答1: ISO C states what the differences are. The int data type is signed and has a minimum range of at least -32767 through 32767 inclusive. The actual values are given in limits.h as INT_MIN and INT_MAX respectively. An unsigned int has a minimal range of 0 through 65535

Why is size_t unsigned?

て烟熏妆下的殇ゞ 提交于 2019-12-17 02:35:18
问题 Bjarne Stroustrup wrote in The C++ Programming Language: The unsigned integer types are ideal for uses that treat storage as a bit array. Using an unsigned instead of an int to gain one more bit to represent positive integers is almost never a good idea. Attempts to ensure that some values are positive by declaring variables unsigned will typically be defeated by the implicit conversion rules. size_t seems to be unsigned "to gain one more bit to represent positive integers". So was this a

How many bits are available for JS-style “integer” math now?

时间秒杀一切 提交于 2019-12-13 07:33:42
问题 While solving my previous question I faced even more funny thing. Try integer math (yes, I know they aren't "too integer" inside) to see how much bits are available: var n = 0xffffffff; // loop over 1P: for(var i=1; i<=1024*1024*1024*1024; i*=16) { var v=(n*i).toString(16); console.log('i='+i+'; v='+v+' ('+v.length*4+')'); } // Output: // i=1; v=ffffffff (32) // i=16; v=ffffffff0 (36) // i=256; v=ffffffff00 (40) // i=4096; v=ffffffff000 (44) // i=65536; v=ffffffff0000 (48) // i=1048576; v

How to make the C++ compiler to use the unsigned to signed trick for optimization of comparison [duplicate]

社会主义新天地 提交于 2019-12-12 02:07:41
问题 This question already has an answer here : Can we and how safe is to “signed” to “unsigned” trick to save one comparison in this case? (1 answer) Closed 4 years ago . So from what I know the following two functions' behavior should be exactly the same. However, if I implement using the first one, the compiler seems can't realize it's equivalent to the second. Is there anyway to hint the compiler to use the second ? In another words, I hate to do the static_cast things... Anyway to avoid it? /

Conversion between signed integer and unsigned integer

扶醉桌前 提交于 2019-12-10 23:35:40
问题 If I cast an unsigned integer to a signed integer then cast back, am I guaranteed to get the original value? For example, does this function always return true for any x on any platform according to the C++ standard? bool f(unsigned int x) { return x == static_cast<unsigned int>(static_cast<int>(x)); } What about this one? bool g(int x) { return x == static_cast<int>(static_cast<unsigned int>(x)); } 回答1: The answer is "no, this is not guaranteed" for both f and g . Here is what the standard