# Wrapping + ints

14 posts

 8130 posts Our level editor, TILED, spat out a lovely number: 2684354587 which also seems to wrap to be 27 since the tile that pops up has value 27. (happens to be the correct tile) How is this possible if the max int value is 2,147,483,647? What math is going on behind the scenes that I’m unaware of. 4717 posts ``` 1111111111111111111111111111111 (int max) 1 0100000000000000000000000011011 (ur large number) 0000000000000000000000000011011 (27) ``` strange indeed. 279 posts Isn’t that a -27 being translated, variously, as a uint and as (the absolute value of) 27? Sorry if I’m missing something obvious; I’m going by qwerber’s bit analysis. Edit: I’m guessing that TILED uses/requires uints, but the wrapper (for whatever reason; I couldn’t find an Integer wrapper in Adobe’s docs) ignores the sign bit…? 6860 posts Originally posted by qwerber:``` 1111111111111111111111111111111 (int max) 1 0100000000000000000000000011011 (ur large number) 0000000000000000000000000011011 (27) ``` strange indeed. Qwerber, your math is off there. 1 0100000000000000000000000011011 <— you missed a 1 in your subtraction. The correct answer is 100000000000000000000000011100 or 536,870,940 1064 posts My money is on confusion between number formats. 2,684,354,587 is 10100000 00000000 00000000 00011011 in binary, so it should be positive when stored as a uint and negative when stored as an int. I don’t see the wrapping to 27, though, since the extra 1 in the beginning makes it wrap to 2^29+27 instead. I have no clue what the Number 27.0 (or -27.0, for that matter) would look like in binary. What’s in a float? \/ Oooh, if UG is reading the number from a ByteArray there’s also the option of having written a Number and reading a uint, or something of that order. Compare the serializing and de-serializing functions to make sure they conduct symmetrical operations. 6261 posts 1010 0000 | 0000 0000 | 0000 0000 | 0001 1011 is -1610612709. it does not overflow 32 bits. it does not wrap to 27. and can be positive if printed as a uint whatever the engine is doing, it’s truncating the value to only the first 29 bits, and ignoring the rest. are you storing/receiving the level data as an AMF3.0 encoded ByteArray? (you use ByteArray::readObject) 8130 posts I don’t know what the TILED engine is doing to get that number, but when put into Flashpunk it does generate a tile with the same graphics of 27. I’ll just go through manually and fix the numbers and set them to their equivalent value. Its just where could that have possibly come from. 6261 posts Originally posted by UnknownGuardian:I don’t know what the TILED engine is doing to get that number, but when put into Flashpunk it does generate a tile with the same graphics of 27. I’ll just go through manually and fix the numbers and set them to their equivalent value. Its just where could that have possibly come from. welcome to the mantra of “if it works well enough DON’T TOUCH IT OR YOU LOSE YOUR HANDS. now get back to work, code monkey” 6860 posts Originally posted by skyboy: welcome to the mantra of “if it works well enough DON’T TOUCH IT OR YOU LOSE YOUR HANDS. now get back to work, code monkey” Words to live by. Now if only I could get the client to think the same way… Me: Can I assume that [some assumption]?" Client: Yes, that’s true. Me: Ok, good, it makes doing this so much easier THREE MONTHS LATER Client: X is different for case Y, it needs to change. Me: I ASKED IF IT WAS ALWAYS X AND YOU SAID YES! Gah! 3011 posts and of course you built the entire system on X being constant. 3750 posts Originally posted by Draco18s:Originally posted by skyboy: welcome to the mantra of “if it works well enough DON’T TOUCH IT OR YOU LOSE YOUR HANDS. now get back to work, code monkey” Words to live by. Now if only I could get the client to think the same way… Me: Can I assume that [some assumption]?" Client: Yes, that’s true. Me: Ok, good, it makes doing this so much easier THREE MONTHS LATER Client: X is different for case Y, it needs to change. Me: I ASKED IF IT WAS ALWAYS X AND YOU SAID YES! Gah! It’s just a minor change! It has to be easy! I’ll even give you an extra \$20! 8130 posts I lied. This number doesn’t wrap to 27. It wrapped to 4. Found that out today when I picked up coding again. Sorry to waste time! 6261 posts Originally posted by UnknownGuardian:I lied. This number doesn’t wrap to 27. It wrapped to 4. Found that out today when I picked up coding again. Sorry to waste time! …4? what the hell. that engine is either using modulo (why?) or black magic (how?). 6860 posts Originally posted by truefire:and of course you built the entire system on X being constant. Not necessarily. Just that it turns a clean algorithm into a bloody mess in order to accommodate. In this case it was a program that steps through a bunch of questions, each answer modifying the final output. In the initial design, nearly all use-cases were nearly identical (like 95%). The change later, which was not unexpected, was that each use case was radically different. Not an issue. Except for 1 question which had to modify a future question’s possible responses. I didn’t have anything set up to allow such a thing. Modify the next question: yes. Not modify the next, but modify the one after that? No. I copped out and just made two nodes for the “not actually different” question that one of which modified the third question. Actually allowing a question to modify any future node was too much of a hassle.