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
58
votes
6 answers

When should I just use "int" versus more sign-specific or size-specific types?

I have a little VM for a programming language implemented in C. It supports being compiled under both 32-bit and 64-bit architectures as well as both C and C++. I'm trying to make it compile cleanly with as many warnings enabled as possible. When I…
munificent
  • 11,946
  • 2
  • 38
  • 55
53
votes
11 answers

Why is int rather than unsigned int used for C and C++ for loops?

This is a rather silly question but why is int commonly used instead of unsigned int when defining a for loop for an array in C or C++? for(int i;i
Elpezmuerto
  • 5,391
  • 20
  • 65
  • 79
52
votes
7 answers

Unsigned Integer in Javascript

I'm working on a page that processes IP address information, but it's choking on the fact that integers are signed. I am using bitwise operators to speed it up, but the 64th bit (signed/unsigned flag) is messing it up. Is there any way to force a…
bradlis7
  • 3,375
  • 3
  • 26
  • 34
49
votes
1 answer

convert unsigned char* to std::string

I am little poor in typecasting. I have a string in xmlChar* (which is unsigned char*), I want to convert this unsigned char to a std::string type. xmlChar* name = "Some data"; I tried my best to typecast , but I couldn't find a way to convert it.
Cyril
  • 1,216
  • 3
  • 19
  • 40
47
votes
5 answers

Difference between unsigned and unsigned int in C

Could you please make it clear what the difference is between unsigned and unsigned int? Maybe some example code would be helpful.
thetna
  • 6,903
  • 26
  • 79
  • 113
44
votes
1 answer

Difference between unsigned and unsigned int in C++

What is the difference between unsigned and unsigned int? This question was already answered for C (there is no difference): Difference between unsigned and unsigned int in C I am interested in knowing whether there is any practical difference in…
paperjam
  • 8,321
  • 12
  • 53
  • 79
43
votes
4 answers

Does C# have an Unsigned Double?

I need to use an unsigned double but it turns out C# does not provide such a type. Does anyone know why?
Amit Raz
  • 5,370
  • 8
  • 36
  • 63
43
votes
6 answers

Why is a negative int greater than unsigned int?

int main(void) { unsigned int y = 10; int x = – 4; if (x > y) Printf("x is greater"); else Printf("y is greater"); getch(); return (0); } Output: x is greater I thought the output would be y…
Slashr
  • 3,139
  • 6
  • 18
  • 13
41
votes
6 answers

C/C++ use of int or unsigned int

In a lot of code examples, source code, libraries etc. I see the use of int when as far as I can see, an unsigned int would make much more sense. One place I see this a lot is in for loops. See below example: for(int i = 0; i < length; i++) { //…
brettwhiteman
  • 4,210
  • 2
  • 29
  • 38
40
votes
3 answers

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

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…
Samir Lakhani
  • 485
  • 6
  • 14
40
votes
5 answers

Why does "int[] is uint[] == true" in C#

Can somebody clarify the C# is keyword please. In particular these 2 questions: Q1) line 5; Why does this return true? Q2) line 7; Why no cast exception? public void Test() { object intArray = new int[] { -100, -200 }; if…
Peervm
  • 482
  • 4
  • 11
40
votes
2 answers

Why is the sign different after subtracting unsigned and signed?

unsigned int t = 10; int d = 16; float c = t - d; int e = t - d; Why is the value of c positive but e negative?
Eugene Kolombet
  • 331
  • 3
  • 5
39
votes
4 answers

c++ uint , unsigned int , int

Hi I have a program that deals alot with vectors and indexes of the elements of these vectors, and I was wondering: is there a difference between uint and unsigned int which is better to use one of the above types or just use int as I read some…
Ismail Marmoush
  • 13,140
  • 25
  • 80
  • 114
38
votes
5 answers

In C, why is "signed int" faster than "unsigned int"?

In C, why is signed int faster than unsigned int? True, I know that this has been asked and answered multiple times on this website (links below). However, most people said that there is no difference. I have written code and accidentally found a…
Devyn Collier Johnson
  • 4,124
  • 3
  • 18
  • 39
37
votes
8 answers

How do you determine the length of an unsigned char*?

How do you determine the length of an unsigned char*?
ads
1 2
3
83 84