Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: MoNksBaNe_Agahnim on March 26, 2004, 01:35 PM

Title: u_long
Post by: MoNksBaNe_Agahnim on March 26, 2004, 01:35 PM
I have seen this before as a reserved word, mainly in bnet bots...

example
u_long u_flags

What is u_long exactly defining the variable u_flags as?
Title: Re:u_long
Post by: K on March 26, 2004, 01:45 PM
Quote from: MoNksBaNe_Agahnim on March 26, 2004, 01:35 PM
I have seen this before as a reserved word, mainly in bnet bots...

example
u_long u_flags

What is u_long exactly defining the variable u_flags as?

probably

typedef unsigned long u_long;
Title: Re:u_long
Post by: iago on March 26, 2004, 01:46 PM
I would assume it's unsigned long.
Title: Re:u_long
Post by: MoNksBaNe_Agahnim on March 27, 2004, 12:22 PM
what exactly does unsigned/signed mean?
Title: Re:u_long
Post by: Adron on March 27, 2004, 12:37 PM
Quote from: MoNksBaNe_Agahnim on March 27, 2004, 12:22 PM
what exactly does unsigned/signed mean?

An unsigned 32-bit integer uses 32 bits to represent the amount. It can take any integer value from 0 to 4294967295.

A signed 32-bit integer uses 31 bits to represent the amount and 1 bit to represent the sign. It can take any integer value from -2147483648 to 2147483647.


Example; 3-bit integer:

The left-most bit is the sign in a signed integer, so all values where that bit is 1 are negative.


binary unsigned signed
000     0        0
001     1        1
010     2        2
011     3        3
100    4        -4
101    5        -3
110    6        -2
111    7        -1


Title: Re:u_long
Post by: Maddox on March 29, 2004, 08:55 PM
Signed integers are represented by two's complement. That is the inversion of the bits + 1.

For example
unsigned int a = 96;
printf("%d %d\n", a, ~a + 1);

Outputs: 96 -96
Title: Re:u_long
Post by: MrRaza on March 30, 2004, 01:00 AM
what does the '~' do?
Title: Re:u_long
Post by: Yoni on March 30, 2004, 01:07 AM
~ is bitwise NOT - it complements each bit in the parameter. (0 becomes 1, 1 becomes 0.)