Page 1 of 1

[Question] Int out of range

Posted: Fri Jun 04, 2010 9:27 pm
by brutus
hey, check the code below! isnt that weird cuz the hexadecimal of 0xffffffff is out of range for Integer and int of 0xffffffff is -1

Code: Select all

 private int	_objectId; 		if (_objectId == 0xFFFFFFFF)		{			// Player canceled enchant			player.setActiveEnchantAttrItem(null);			player.sendPacket(new SystemMessage(SystemMessageId.ELEMENTAL_ENHANCE_CANCELED));			return;		} 

Re: [Question] Int out of range

Posted: Sat Jun 05, 2010 12:07 am
by JIV
if (_objectId == 0xFFFFFFFF)
and
if (_objectId == -1)

is same. or what is the question?

Re: [Question] Int out of range

Posted: Sat Jun 05, 2010 1:13 pm
by brutus
JIV wrote:if (_objectId == 0xFFFFFFFF)
and
if (_objectId == -1)

is same. or what is the question?
exactly, thats what i asked :) so you guys use out of range ints to get the -1?
thank you anyways

Re: [Question] Int out of range

Posted: Sat Jun 05, 2010 4:39 pm
by JIV
its not out of range.

Re: [Question] Int out of range

Posted: Sat Jun 05, 2010 4:51 pm
by brutus
JIV wrote:its not out of range.
isnt 0xFFFFFFFF = 4294967295 ?
max int is 2.147..

Re: [Question] Int out of range

Posted: Sat Jun 05, 2010 4:56 pm
by JIV
that depends on how many bytes you have

Re: [Question] Int out of range

Posted: Sat Jun 05, 2010 5:11 pm
by brutus
JIV wrote:that depends on how many bytes you have
anyways, it was a stupid question :| as you said its not out of range since Integer contains all positive and negative numbers and the total is 0xFFFFFFFF :| i didnt thought that the objectid can be -1 thats why i asked.. thanks for your time

Re: [Question] Int out of range

Posted: Sat Jun 05, 2010 6:58 pm
by UnAfraid
brutus wrote:
JIV wrote:its not out of range.
isnt 0xFFFFFFFF = 4294967295 ?
max int is 2.147..
http://en.wikipedia.org/wiki/Integer_(computer_science)

:)

Re: [Question] Int out of range

Posted: Sat Jun 05, 2010 11:05 pm
by wasabi2k
brutus wrote:
JIV wrote:its not out of range.
isnt 0xFFFFFFFF = 4294967295 ?
max int is 2.147..
this is wrong cuz INT is a signed integer which means that the last bit is used to say whereather it is negative or positive thats why the max size of a 32bit integer is 2^31 and not 2^32 since it needs a bit for negative values.

also if i am correct negative integers count the opposite way of positive integers so 0x00000001 = 1 and 0x00000002 = 2 but for negative its 0xFFFFFFFF = -1 and 0xFFFFFFFD = -2

i hope my explenation is clear D: