unsigned-integer Questions

5

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, ...
Damnatory asked 31/12, 2016 at 4:53

7

Solved

In Jens Gustedt's book Modern C, on page 59, he explains how signed integers can be emulated using unsigned integers. His example code shows how one can implement a comparison of two unsigned integ...
Vaporetto asked 24/10, 2023 at 11:38

9

Solved

I am specifically thinking about unsigned int. Here is a practical example: what do you do when your identity column maxes out? It's possible to either go BigInt (8 bytes storage instead of 4) or...
Though asked 15/12, 2010 at 15:57

1

Solved

I have a situation where I need to pack 16 bits into a 64-bit number and later read them back as a signed integer in the range [ -32768, 32768 ). The method I have chosen for this is to compute the...
Mcneese asked 1/9, 2023 at 17:59

13

Consider unsigned integer representation. How many bits will be required to store a decimal number containing: i) 3 digits ii) 4 digits iii) 6 digits iv) n digits I know that the range of the un...
Compressibility asked 22/8, 2011 at 15:47

2

I tried: #include <vector> int main () { std::vector<int> v; int size = v.size; } but got the error: cannot convert 'std::vector<int>::size' from type 'std::vector<int&g...
Derivation asked 2/7, 2015 at 23:53

4

Solved

Kotlin 1.3 introduced unsigned integer types, but I can't seem to figure out how to get an unsigned integer from a ByteArray in Kotlin JVM. Kotlin Native has a convenient ByteArray.getUIntAt() met...
Indorse asked 26/12, 2018 at 7:46

5

Solved

Can a field of type models.PositiveIntegerField contain a 0 value? I'm doing something like: points = models.PositiveIntegerField() Thanks, I know I should try it myself, but I haven't a Django en...

7

Solved

I have an unsigned int number (2 byte) and I want to convert it to unsigned char type. From my search, I find that most people recommend to do the following: unsigned int x; ... unsigned char c...
Rooted asked 25/4, 2012 at 16:26

2

Solved

How can I emulate 32bit unsiged integers without any external dependencies in Javascript? Tricks with x >>> 0 or x | 0 don't work (for multiplication, they seem to work for addition / subt...
Guiltless asked 28/7, 2012 at 18:28

3

Solved

I have seen floating point bit hacks to produce the square root as seen here fast floating point square root, but this method works for floats. Is there a similar method for finding the integer squ...
Juneberry asked 1/2, 2021 at 1:27

2

I have a question about unsigned integer in C/C++. They and the results of operations on them should always be positive or equal to zero but it does not look the case with uint16_t difference. uint...
Bicentennial asked 1/1, 2022 at 8:37

1

Solved

I know that unsigned integers are infamous and generally avoided by C++ devs. I have a class with two int member variables that should not contain negative values: . . . private: int m_Y_AxisLen; ...

3

Solved

I've seen this kind of question asked before, but supplied answers don't clear everything for me. When this question is posted it is usually accompanied by next example: #include <iostream> ...
Befog asked 22/6, 2021 at 20:39

5

Solved

I have made some research on Stackoverflow about reverse for loops in C++ that use an unsigned integer instead of a signed one. But I still do NOT understand why there is a problem (see Unsigned in...
Bazemore asked 28/1, 2012 at 8:54

4

Solved

I'm in a dilemma about saving date and time values in MySQL's TIMESTAMP format vs in a custom UNSIGNED INT format. The main considerations here are speed of retrieval, appropriate range calculation...
Faintheart asked 11/8, 2011 at 16:3

4

Solved

Is there a way to declare a 32-bit unsigned integer in PowerShell? I'm trying to add an unsigned (begin with 0xf) i.e. 0xff000000 + 0xAA, but it turned out to be a negative number whereas I want i...
Entertaining asked 16/5, 2012 at 20:22

2

Solved

#include <iostream> #include <cstdint> using namespace std; static_assert(-1 == numeric_limits<uint64_t>::max()); // ok static_assert(-1 == numeric_limits<uint32_t>::max()...

9

Solved

I am trying to convert 65529 from an unsigned int to a signed int. I tried doing a cast like this: unsigned int x = 65529; int y = (int) x; But y is still returning 65529 when it should return -...
Schist asked 29/11, 2011 at 20:29

6

Solved

I came across this post (What is the difference between tinyint, smallint, mediumint, bigint and int in MySQL?) and realized that PostgreSQL does not support unsigned integer. Can anyone help to e...
Poser asked 28/12, 2013 at 1:44

10

Solved

Using integer math alone, I'd like to "safely" average two unsigned ints in C++. What I mean by "safely" is avoiding overflows (and anything else that can be thought of). For instance, averaging...
Frasco asked 28/9, 2010 at 19:43

2

Solved

So, I am new to programming in c++ and i came across this question where i need to calculate pow(2,n)/2 where n>64 ? i tried using unsigned long long int but as the limit of the c++ is only 2^64. ...
Presbyterate asked 2/8, 2019 at 17:39

6

Solved

I am currently working through Accelerated C++ and have come across an issue in exercise 2-3. A quick overview of the program - the program basically takes a name, then displays a greeting within ...
Extortion asked 7/9, 2010 at 17:6

5

Solved

There are a variety of questions written here about QSpinBox's limitation of using an int as its datatype. Often people want to display larger numbers. In my case, I want to be able to show an unsi...
Zischke asked 27/10, 2014 at 5:3

5

What is the difference between signed and unsigned int?
Batholith asked 21/4, 2011 at 5:21

© 2022 - 2024 — McMap. All rights reserved.