[Question] Int out of range

This is not a Support area! Discuss about the Server here. Non-Server related discussion goes in Off-Topic Discussion.
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
brutus
Posts: 325
Joined: Sat Nov 10, 2007 4:18 pm
Location: Bulgaria

[Question] Int out of range

Post 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;		} 
User avatar
JIV
L2j Veteran
L2j Veteran
Posts: 1882
Joined: Sun Jan 06, 2008 8:17 pm
Location: Slovakia
Contact:

Re: [Question] Int out of range

Post by JIV »

if (_objectId == 0xFFFFFFFF)
and
if (_objectId == -1)

is same. or what is the question?
User avatar
brutus
Posts: 325
Joined: Sat Nov 10, 2007 4:18 pm
Location: Bulgaria

Re: [Question] Int out of range

Post 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
User avatar
JIV
L2j Veteran
L2j Veteran
Posts: 1882
Joined: Sun Jan 06, 2008 8:17 pm
Location: Slovakia
Contact:

Re: [Question] Int out of range

Post by JIV »

its not out of range.
User avatar
brutus
Posts: 325
Joined: Sat Nov 10, 2007 4:18 pm
Location: Bulgaria

Re: [Question] Int out of range

Post by brutus »

JIV wrote:its not out of range.
isnt 0xFFFFFFFF = 4294967295 ?
max int is 2.147..
User avatar
JIV
L2j Veteran
L2j Veteran
Posts: 1882
Joined: Sun Jan 06, 2008 8:17 pm
Location: Slovakia
Contact:

Re: [Question] Int out of range

Post by JIV »

that depends on how many bytes you have
User avatar
brutus
Posts: 325
Joined: Sat Nov 10, 2007 4:18 pm
Location: Bulgaria

Re: [Question] Int out of range

Post 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
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: [Question] Int out of range

Post 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)

:)
Image
wasabi2k
Posts: 110
Joined: Sun Oct 08, 2006 4:22 pm

Re: [Question] Int out of range

Post 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:
Post Reply