Questions tagged [unsigned]

An unsigned variable is a variable that can only represent non-negative numbers.

An unsigned variable is a variable that can only represent non-negative numbers, as opposed to a signed variable which can represent both positive and negative numbers.

1251 questions
7
votes
1 answer

double to unsigned int / char

I read here, that: According to C99 §6.3.1.4 footnote 50: The remaindering operation performed when a value of integer type is converted to unsigned type need not be performed when a value of real floating type is converted to unsigned type.…
mb84
  • 683
  • 1
  • 4
  • 13
7
votes
3 answers

C Unsigned int providing a negative value?

I have an unsigned integer but when i print it out using %d there is sometimes a negative value there?
Dannul
  • 81
  • 1
  • 2
  • 4
7
votes
2 answers

How to unsign an APK via command line in Windows

I work in a QA department that receives APKs signed with development keys. When we want to sign one of these builds for purchase testing, I typically use 7zip to open the APK and delete the META-INF folder, and then I run a script that assists me…
jpelletier
  • 133
  • 1
  • 8
7
votes
4 answers

What does the unary operator "-" do on unsigned data types in C/C++ (and on different compilers)?

For example: unsigned int numA = 66; // or anything really unsigned int numB = -numA; unsigned int numC = numA & numB I understand that the bitwise complement operator can be used to get the two's complement (in conjunction with a +1). The reason I…
Eric Thoma
  • 5,905
  • 6
  • 30
  • 40
7
votes
5 answers

Where did the leading 1 means negative number in signed int arise from?

Even though I read a number of articles that say that mostly 2's complement is used to represent the negative numbers in a signed integer and that that is the best method, However for some reason I have this (below) stuck in my head and can't get…
Kingkong Jnr
  • 1,128
  • 4
  • 18
  • 29
6
votes
5 answers

Reading 'unsigned int' using 'cin'

I am trying to read an unsigned int using cin as follows: #include #include using namespace std; int main(int argc, char* argv[]) { unsigned int number; // UINT_MAX = 4294967295 cout << "Please enter a number…
user1250836
  • 63
  • 1
  • 4
6
votes
4 answers

How does an adder perform unsigned integer subtraction?

Suppose that A and B are signed positive integers, then for A-B, it's calculated using A+2's complement of B. For example, in a 4-bit binary system, for signed integers, we have 7-3=0111-0011=0111+1101=(1)0100, the 1 in the bracket is the carry bit.…
JohnTang
  • 73
  • 1
  • 4
6
votes
1 answer

c++ find char in vector of unsigned chars

I have the problem with the following code: message is vector vector::iterator pos = message.begin(); vector::iterator start = message.begin(); vector::iterator end = message.end(); pos =…
M.K.
  • 640
  • 1
  • 10
  • 23
6
votes
2 answers

C++ reverse 'for' loop

I have a vector: std::vector vec = {1, 2, 3}; And I want to make a reverse for loop. It works, when I write: for(int i = vec.size() - 1; i >= 0; --i) { std::cout << i << std::endl; // 2, 1, 0 } But I get a very large number (like…
asd
  • 266
  • 7
  • 15
6
votes
4 answers

casting signed to unsigned

is it correct to do this? typedef unsigned int Index; enum { InvalidIndex = (Index) -1 }; I have read that it is unsafe across platforms, but I have seen this in so many "professional" codes...
relaxxx
  • 7,566
  • 8
  • 37
  • 64
6
votes
2 answers

Does C provide an operator to check the signedness of a type?

If I'm using a library which currently uses a particular numeric type alias, e.g. typedef uint32_t library_type; void library_function(library_type x); How would I ensure that code which needs to pass in a value from a different type remains…
natevw
  • 16,807
  • 8
  • 66
  • 90
6
votes
4 answers

Difference between signed and unsigned data types?

main() { char i=255; printf("\n%x\n",i); } output:ffffffff main() { u_char i=255; printf("\n%x\n",i); } output:ff What is happening here? Kindly explain the output to me with some good links. This is a very basic thing I guess and…
pflz
  • 1,891
  • 4
  • 26
  • 32
6
votes
3 answers

What's the difference between (size_t)-1 and ~0?

I've seen both (size_t)-1 and ~0 used to represent large numbers, or numbers with all their bits flipped. Is there any difference between the two? If so, what is it? I found this question: What is the difference between -1 and ~0, however it did not…
S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
6
votes
5 answers

Does VB6 support unsigned data types?

In order to settle a bet with one of my colleagues, I would like to find out if VB6 natively supports any unsigned data types. I believe the answer to be "no", but I can't seem to find any official documentation confirming that. A simple link to a…
Fueled
  • 8,776
  • 9
  • 29
  • 31
6
votes
5 answers

Efficiently convert an unsigned short to a char*

What would be an efficient, portable way to convert a unsigned short to a char* (i.e. convert 25 to '25'). I'd like to avoid things such as getting (std::string) strings involved. Performance is important in this case since this conversion will…
jCuga
  • 1,523
  • 3
  • 16
  • 28