unsigned-integer Questions

5

Solved

After getting advised to read "C++ Primer 5 ed by Stanley B. Lipman" I don't understand this: Page 66. "Expressions Involving Unsigned Types" unsigned u = 10; int i = -42; std::cout << i + ...
Ziwot asked 14/1, 2019 at 22:26

1

Solved

What does the C standard say about: uint32_t a = 0x11223344; uint16_t b = a; When printed, I am getting 0x3344, which makes sense; so this must be legal and correct behaviour?
Exhortation asked 3/1, 2019 at 20:5

1

Solved

enum Some_Flag { SOME_FLAG_A = 0x00000000u, SOME_FLAG_B = 0x00000001u, SOME_FLAG_C = 0x00000002u, /* ... */ SOME_FLAG_Z = 0x80000000u, }; uint32_t a; a = SOME_FLAG_Z; Assuming 32 bit intege...
Scutcheon asked 8/12, 2018 at 11:11

3

Solved

I came across a situation just recently in which an unsigned integer would have been really useful (e.g. any negative value would not make sense etc.). Surprisingly, I discovered that Kotlin does n...
Osprey asked 7/5, 2018 at 19:56

1

I have an int64 variable which contains a negative number and I wish to subtract it from an uint64 variable which contains a positive number: var endTime uint64 now := time.Now().Unix() endTime = ...
Damara asked 12/6, 2018 at 10:58

1

Solved

I experimented today with how the compiler determines the types for numbers declared as var. var a = 255; //Type = int. Value = byte.MaxValue. Why isn't this byte? var b = 32767; //Type = int. Val...
Cadet asked 21/5, 2018 at 10:51

4

Solved

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 t...
Platas asked 16/4, 2012 at 2:30

2

Suppose I have two integers x and y, and I want to check whether their sum is larger than UINT_MAX. #define UINT64T_MAX std::numeric_limits<uint64_t>::max() uint64_t x = foo(); uint64_t y =...
Rupertruperta asked 28/2, 2018 at 8:3

2

Solved

I’m trying to implement a function which accepts only unsigned integral types. Below is what I’ve tried so far. It works for "unsigned int", but why doesn’t this compile for an "unsigned short?" #...
Rooks asked 22/1, 2018 at 19:31

2

C++ standard If a C++14 implementation includes padding bits in the underlying bytes of an unsigned int , does the standard specify if bitwise operations must not be performed on padding bits ? A...

1

I was reading a book (CSAPP) . In the book it is written that- floating point addition satisfies the following monotonicity property : if a>=b then (x + a) >= (x+b) for any value a,b and x o...

7

Solved

I need generate random 64-bit unsigned integers using C. I mean, the range should be 0 to 18446744073709551615. RAND_MAX is 1073741823. I found some solutions in the links which might be possible ...
Matthia asked 8/10, 2015 at 8:3

8

I was looking at this video. Bjarne Stroustrup says that unsigned ints are error prone and lead to bugs. So, you should only use them when you really need them. I've also read in one of the questio...
Elamitic asked 22/5, 2015 at 11:11

5

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...
Herbertherbicide asked 28/9, 2010 at 10:59

1

Solved

Brand new to assembly need some help with unsigned arithmetic. Converting from a C program is that means anything. Using: Linux NASM x86 (32 Bit) I want to read in a number from the user. I ...
Vadose asked 14/3, 2017 at 20:9

5

I Learned About 2's Complement and unsigned and signed int. So I Decided to test my knowledge , as far as i know that a negative number is stored in 2's complement way so that addition and subtract...
Heikeheil asked 30/12, 2016 at 16:0

4

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 examp...

1

Solved

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 t...
Hydrogeology asked 26/5, 2016 at 1:57

3

Solved

Suppose you have this: struct Foo { Foo(unsigned int x) : x(x) {} unsigned int x; }; int main() { Foo f = Foo(-1); // how to get a compiler error here? std::cout << f.x << std::en...
Iyar asked 22/3, 2016 at 18:10

1

For example the code below int a = -7777; int b = 10; cout<< a % b<<endl; cout<<(a+b)%b<<endl; cout<< -7777%10 <<endl; The results are: -7 -7 -7 but if I c...
Francinafrancine asked 20/3, 2016 at 15:30

4

Solved

I have seen the following code in the book Computer Systems: A Programmer's Perspective, 2/E. This works well and creates the desired output. The output can be explained by the difference of signed...

3

Solved

I have a question (or more likely a bug report) about bit shifting behavior in Delphi (tested in Borland Delphi 7). Target: perform an "Arithmetic" bitwise shift right with any number. This means...
Adore asked 24/8, 2015 at 18:45

6

Solved

I'm using the sqlite3 library that is available at sqlite.org. I have some unsigned longs that I would like store in a database. I do not want to construct the query myself and leave it open to so...
Salacious asked 13/12, 2011 at 21:54

9

Solved

I just want to know what is the benefit/usage of defining ZEROFILL for INT DataType in MySQL? `id` INT UNSIGNED ZEROFILL NOT NULL
Empress asked 10/3, 2011 at 6:57

4

Solved

I have a simple program. Notice that I use an unsigned fixed-width integer 1 byte in size. #include <cstdint> #include <iostream> #include <limits> int main() { uint8_t x = 12;...

© 2022 - 2024 — McMap. All rights reserved.