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
5
votes
1 answer

unsigned long vs size_t causes function overload fail

I defined a function: void myfunc(size_t param1, size_t param2){ ... } it works fine. But when I try to overload this function void myfunc(unsigned long param1, unsigned long param2){ ... } It fails to compile with the following message: error:…
Harvey Dent
  • 327
  • 2
  • 14
5
votes
1 answer

warning C4146 minus operator on unsigned type

I have this code from a library I want to use. On compiling, I get the following warning: warning C4146: unary minus operator applied to unsigned type, result still unsigned inline int lastbit (uint32_t v) { int r; static const int…
user1930254
  • 1,251
  • 5
  • 17
  • 32
5
votes
1 answer

VHDL unsigned vector vs integer comparison

In vhdl, assume I have an unsigned vector defined as follows: signal s_col_rd_check : unsigned(7 downto 0); Now, whether I use the following library, use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; Or the following use…
Rudy01
  • 1,027
  • 5
  • 18
  • 32
5
votes
2 answers

Can Java use unsigned comparison for general in-range tests?

I've seen that JITC uses unsigned comparison for checking array bounds (the test 0 <= x < LIMIT is equivalent to 0 ≺ LIMIT where ≺ treats the numbers as unsigned quantities). So I was curious if it works for arbitrary comparisons of the form 0 <= x…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
5
votes
3 answers

MySQL integer unsigned arithmetic problems?

Does MySQL (5.0.45) like to do strange internal typecasts with unsigned maths? I am storing integers unsigned but when selecting basic arithmetic I get outrageous numbers: mysql> create table tt ( a integer unsigned , b integer unsigned , c float…
Jé Queue
  • 10,359
  • 13
  • 53
  • 61
5
votes
4 answers

SSE Compare Packed Unsigned Bytes

I'm trying to use the SSE instructions to do some image filtering. The image I'm using has a byte per pixel (255 greyscale) and I need to compare the unsigned packed bytes using a greather than comparison. I've looked into the intel's manual and the…
Lautaro
  • 362
  • 3
  • 14
5
votes
3 answers

How to initialize an unsigned char array of variable length?

I read through this(How to initialize a unsigned char array?), but it doesn't quite answer my question. I know I can create an array of strings like this: const char *str[] = { "first", "second", "third", "fourth" }; and if I want to…
Rich G.
  • 61
  • 1
  • 1
  • 5
5
votes
4 answers

Why C compiler cannot do signed/unsigned comparisons in an intuitive way

By "intuitive" I mean given int a = -1; unsigned int b = 3; expression (a < b) should evaluate to 1. There is a number of questions on Stackoverflow already asking why in this or that particular case C compiler complains about signed/unsigned…
ayurchen
  • 386
  • 3
  • 9
5
votes
0 answers

clamping unsigned ints

What is the correct way to clamp unsigned ints? For example, say I have: unsigned int ui = 5U; Now I want to subtract a value from it: ui = Clamp(ui - MAGIC_VALUE, 0, 255); I would like ui to contain 0 if MAGIC_VALUE >= 5. However, I can't just…
user987280
  • 1,578
  • 1
  • 14
  • 24
5
votes
2 answers

accessing unsigned integer values in fortran

If I have a c_int8_t variable in Fortran and want to interpret the underlying bits as an unsigned integer (for indexing rather than for any arithmetic) what is the most efficient way to do the conversion? I want to do something like X(…
robince
  • 10,826
  • 3
  • 35
  • 48
5
votes
3 answers

Comparing signed and unsigned values in objective-c

Recently I have encountered a problem with comparing signed and unsigned values in objective-c. Here is an example of this problem: NSArray *array = [NSArray array]; NSLog(@"Count = %d", array.count); NSLog(@"Count - 2 = %d", array.count - 2); if…
Piotr
  • 5,543
  • 1
  • 31
  • 37
5
votes
4 answers

cannot convert from 'unsigned char *' to 'char *'

Possible Duplicate: C++ style cast from unsigned char * to const char * I have the unsigned char* digest; which is the output of a program and i would like to pass it to a char* S1; I type char* S1=digest; and does not work
Hashed
  • 57
  • 1
  • 2
  • 6
5
votes
1 answer

VHDL assigning decimal values to std_logic_vector

I'm trying to add a decimal value to a 10 bit std_logic_vector without having to describe every bit. Though it might not be worth the trouble in this particular scenario, i believe it will be very good to know in the future. So far i have: …
Laserbeak43
  • 595
  • 2
  • 8
  • 21
5
votes
2 answers

java: writing integers to file as unsigned 8 bit integer

In java, how do I write integers to a file so that they are unsigned 8 bit integers (within range 0 to 255) ? Is it enough that the numbers are of type int and within 0-255, or do I need to convert them to some other type first? I think it's just…
Joel Feodiyoup
  • 53
  • 1
  • 1
  • 3
5
votes
4 answers

Is it a best practice to use unsigned data types to enforce non-negative and/or valid values?

Recently, during a refactoring session, I was looking over some code I wrote and noticed several things: I had functions that used unsigned char to enforce values in the interval [0-255]. Other functions used int or long data types with if…
Casey
  • 10,297
  • 11
  • 59
  • 88