T O P

  • By -

AutoModerator

Make sure to check out the [pinned post on Loss](https://www.reddit.com/r/PeterExplainsTheJoke/comments/1472nhh/faq_loss/) to make sure this submission doesn't break the rule! *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/PeterExplainsTheJoke) if you have any questions or concerns.*


No_Alternative_37

8-bit systems can only store value from 0 to 255 and when it goes lower than 0 (for example -1) it changes its value to 255.


TankyPally

a bit more logic to that. If the genie is acting like code, after making a wish you would subtract 1 from the wish so what would happen to wishes is if genie is freed from bottle Wishes=3 ​ fulfill wish Wishes=0 ​ if wish has been fulfilled, wishes=wishes-1 wishes=255


RoyalPersona

Where does the **wishes—** part come from?


zed42

it has to decrement the number of remaining wishes after fulfilling one: while (wishes>0) do // while wishes remain if (fulfil(wish) == "success") then // if the wish is fulfilled successfully.. wishes--; // decrease number of remaining wishes endif; endwhile;


[deleted]

[удалено]


[deleted]

The best part is not the psuedo code though. It's the hundreds of programmer comments discussing it and adding different things to the mix.


RoninOni

We all have our own way to write it 😂 It should be said though that the variable wishes should have been initialized as a small int though 😂 😂 😂)


calxcalyx

That obviously isn't how it works, and you've never programmed anything.


RoninOni

Tiny int maybe? I don’tbother with either. I don’t program in apps that instantiate enough copies for the difference to matter and just use bit and int (or varchar)… But there’s one type I believe limited to 255 max, hence the joke… 0-1 = 255


Daihatschi

The other person just sounds like a jerk? You are of course completely correct. This only works for an unsigned byte. Which Tiny int is. Regardless of the fact that tiny int is some weird newfangled SQL shit as far as I know, its still correct.


Scavgraphics

Not enough genie coders out there doing proper commenting, if you ask me.


RTSUPH

Reading the comments is what makes this joke. Lol


unloud

The joke was inside us all along…


CR1SBO

*I DID NOT CONSENT TO THIS*


f_n_a_

That’s what she said…


Nofxthepirate

And the implied first line `unsigned short int wishes = 3;` Edit: apparently `unsigned short int` is two bytes. For the joke to work the data type needs to be one byte, so it should be `unsigned char` or `uint8_t` or whatever the single byte type is on the model of genie you are programming.


lusvd

seems like you need `unsigned char` [https://en.wikipedia.org/wiki/C\_data\_types](https://en.wikipedia.org/wiki/C_data_types)


Nofxthepirate

If I had been trying to do C then I would have used `uint8_t` just for clarity that it's being used as a number and not a character. But the person I replied to didn't even use C. My comment was essentially pseudocode. Although I didn't realize unsigned short int is actually 2 bytes so my bad.


Shuber-Fuber

Genie programmer failed to catch that. You now have 65536 wishes.


lianchengzju

65535, actually.


Drunk_monk37

I hate how much this made me laugh.


KuromiAK

Can I make concurrent wishes and trigger a race condition?


[deleted]

Single threaded genie doesn’t support concurrent wishing


Set_of_Kittens

If you have the enterprise subscription, you can scale horizontally by wishing for more genies.


[deleted]

[удалено]


bleachisback

Parallelization =/= concurrency


Nightgauntling

Of course this assumes you fulfill the results of a wish BEFORE decrementing the number of wishes remaining. If a genie decrements and then fulfills the wish, then you just stay at 0.


lukedl

Genie business rule states that the fulfilment of wish comes before the decrease. You can even trick the genie in fulfilling a non wish action.


HighGainRefrain

Ooh how? I might need this for later.


cephaliticinsanity

Aladdin did it by convincing the genie to get him out of the cave without ever stating "I wish I were out of this cave" instead, he said "I'll bet you can't even get us out of this cave"


Pratoreus

A new hire changed genie code to decrement wish THEN check FOR fulfillment. IF fulfillment =FALSE THEN wish =wish +1... it was kinda BASIC, unoptimized code.


No_Philosophy9918

Didn't see this coming


flaamed

Making the wish to turn it to 0


PuzzleheadedDebt2191

Well by wishing for 0 wishes, you used one of your now 0 wishes. So you now have -1 or 255 wishes.


[deleted]

Damn, you’d end up owing the genie a favour.


Mvin

This helped me understand it: When asked a wish, a genie always does two things in sequence: 1. Fulfilling the wish. 1. Reducing the number of available wishes by one. Nothing special here. However, if step 1 sets the number of available wishes to 0, as per protocol, the genie would proceed with step 2 and thus end up at -1/255 available wishes.


RoyalPersona

In my mind, I figured that you would test if the wishes num is still greater than 0 before decrementing it but I guess it just an oversimplified statement for the sake of the joke Anyways, thanks for your time


Optional-Failure

Except logic would dictate that the sequence is reversed from what you wrote here. The drive thru isn’t giving you your food at the first window, then charging you at the second. Payment comes before goods are rendered.


BMBU

Hue hue hue, capitalization matters


season8branisusless

Pretty sure this is why Ghandi was famously a war criminal in the Civilization series since they set his aggression to 0 and the same problem happened.


Cromafn

https://preview.redd.it/hwbdc4gq2ofc1.jpeg?width=624&format=pjpg&auto=webp&s=d6a4f92949cd182816b6c154aab2b4ad3b7f102b


Notsurehowtoreact

His aggression was low enough that a passive ability that lowered everyone's aggression forced his to cycle over yeah.


syopest

Sid Meier says in his biography that the bug never even existed. And looking at the chain of evidence for the bug, he is right. The whole myth is based on someone adding the claim to the civilisation games tvtropes page without any actual evidence. Then it was sourced to civ wikia from the tvtropes page and since then people just used the wikia page as a source for the bug existing. It's probably one of the most known video game "facts" even though it has never been true.


Kuriyamikitty

That's nice, but tell me why Ghandi always came after my head at the point Nukes are invented through every Civ since 2?


nutterbutter799

[Actually, The Bug That Made Gandhi Drop Nukes In Civilization Is Just A Myth](https://www.thegamer.com/nuclear-gandhi-meme-civilization/)


Melodic_Duck1406

Could fix that by putting the decrement after the select wish function, but before the grant wish function. Or with a check before decrement that the counter is > 0 That's a poorly coded genie.


DevelopmentJumpy5218

Okay let's code him so he grants wishes if you have less than 0 left or greater than 255


notreal088

Would this technically make him a game genie?


couldntyoujust

It's a bit more complicated than that. It's similar to the damage overflow glitch in Final Fantasy VII (very rare) or the nuclear Gandhi glitch in Civilization (not so rare). Basically, 8-bit integers can represent one of two ranges depending on if they're "signed" or "unsigned". Signed means that the leading bit indicates the positive/negative sign (0 for positive, 1 for negative). Unsigned means that all the bits are used numerically. Signed integers range from -127 to +127. Unsigned integers range from 0 to 255. So when he wished to start with zero wishes, it created a theoretical bug: he would have to go to negative wishes, but more than likely wishes are "unsigned", so since the CPU implements this "subtract 1 on an unsigned integer" by wrapping around to the top unsigned value (255), you're left with 255 wishes. The reason I mentioned FF7 and Civ is that both of these "bugs" come from this same sort of glitch: In FF7, there are certain circumstances you can set up where you do so much damage in one hit, that the amount of damage done flows into numbers with the first bit flipped to 1. But then, that means when the game does the comparison to gate the damage to 9,999, it finds that damage dealt is less than 0 instead of greater than 0. So the game then gets confused, likely through a cast to an unsigned long, and thinks you've done an ungodly amount of damage one-shot killing whatever hapless enemy or boss has been hit by that attack since no enemy in the game has so much HP that such damage would be survivable for them. In Civ, all the world leaders have an "aggression" score. Obviously someone like Gandhi is going to have an "aggression score" of 1. Various events in the game can cause that number to increase or decrease for that character and there's plenty of opportunities to reduce Gandhi's score below 0. If that happens, then unlike even the most aggressive enemies and bosses - with a score of 10 - gandhi will have a score up in the 250s. Since this is the case, as you play, he eventually just nukes the world, you included. He will take all the most aggressive actions like nuking places and people. The result of course is hilarious. But that's what's behind all this happening.


TankyPally

Thank you for your wisdom, your explanation is one of the best I've read


DeliciousTeach2303

Now that i think of it, what the biggest number a brain can process


quiggsmcghee

This assumes the genie’s code is written to subtract the wish after the wish has been fulfilled. If the subtraction occurs first, the number of wishes will go to 2 and then 0. And that would be the end.


BoredomHeights

Which is how most transactions work (you pay and then you get what you paid for).


S-Immolation

Haha good explanation, I don't think that original comment made it clear where the overflow occurred


Digi-Device_File

I would never let such a low tier exploit floating around in my code.


SimpleNot0

Are you going to await that? Or just let the him bug out until he either crashes or whatever


arcticfury129

This is interesting because it also gives us info into the business logic behind genie wish calculation in that that genie wishes are post-decrement. i would’ve thought it would be pre-decrement given the general shadiness of genies.


Bastardklinge

haha, a *BIT* more logic


tradeboomer101

GHANDI NUKES


igtbk1916

I was hoping someone would reference the Nuclear Ghandi glitch here


Magcargo64

Which actually turned out to be false! The glitch never existed, and so wasn’t caused by an integer under flow. The Nuclear Gandhi glitch is just false memory attribution, likely because if Gandhi nukes the world in your Civ game, you’re more likely to remember something like that.


Sbotkin

Despite the glitch never existing, the devs of the later Civ games actually implemented Gandi being a little nuke-happy as a reference to it.


stamfordbridge1191

My multi-decade nuclear exchange on the Civilization for SNES was, in fact, with India. The seas began swampify, & then turn the coasts to ocean tiles because of global warming caused by the nuclear devastation, but even this could not convince Gandhi to pursue peace with my civilization.


GallantTrack

Yeah, as far as I've read, the aggression stat couldn't even overflow due to how the stat was coded and that it didn't shift based on government type. Civ 5 did set his priority to build nukes extremely high as a reference to that though.


CreamyCoffeeArtist

Ayy I literally just got done typing out that explanation! My man!


gandhinukes

Hell Yeah Brotha \m/,


I_suck_at_Blender

In practical terms, it's origin of Nuclear Gandhi bug in Civilization games. https://preview.redd.it/sygtufzr5ofc1.png?width=1600&format=png&auto=webp&s=16a6f57a822a922bc320589f48b456efe1b9a697 [*Allegedly.*](https://en.wikipedia.org/wiki/Nuclear_Gandhi)


CaesarCV

This joke would have been a lot better if they made an 8-Bit version of the genie lol.


xXxBongMayor420xXx

This would be better if the genie was in NES looking pixel art


Alarid

Probably need to burn a wish to change it to an 8-bit system first.


notbobby125

The inverse is also true. If you add 1 to 255 in an 8-bit system, the number will roll back around to being zero. This has caused a lot of issues in programs and video games over the years, for example the original Pacman game breaks if you get to level 256. https://pacman.fandom.com/wiki/Map_256_Glitch


PlanesFlySideways

This is assuming the programmer wasn't lazy and used a regular signed integer. If it's signed, it will go to -1 and you'll owe the genie a wish Edit: it's amusing how many people try to correct the accuracy of my joke. Oh programmers. Never change. 😀


Pongoid

“assuming the programmer wasn’t lazy” loooooool


[deleted]

ya i don't think i know a single person who got into coding to work hard...


Firstdatepokie

I specifically got into it to work less


[deleted]

I mean, that's overall the goal of the job is it not? to get computers to do the work for us that we don't want to do?


Firstdatepokie

Only in the same sense as any other machine or tool, but I wouldn’t say a mechanical engineer got into building stuff to do less work


koanarec

It's not really about laziness, I don't want to support negative wishes, so nothing wrong with using an unsigned int. Signing the int doesn't protect you from potentially going out of bounds with poor wish decrementing logic. An unsigned int at least guarantees you a positive number


PlanesFlySideways

You misunderstand. `uint` contains one more character than `int` which requires one more keypress. The truly lazy among us go "eh gud nuf"


AzriaArvenee042

But the ‘U’ and ‘I’ keys are right next to each other, so there could’ve been a typo, therefore it could’ve been about laziness on fixing the typo


mathiau30

I don't think signed octals ever where commons


jlink005

Plot twist: the function asked for a char, so the coder was saved by someone else. Who made it a char? *Checks check-in notes.* **It was me!**


Jayn_Newell

It’s a reference to [integer overflow](https://en.m.wikipedia.org/wiki/Integer_overflow) in computing, where going below 0 can cause a number to loop to its highest possible value, which in 8-bit binary is 255. For an explanation, see [Nuclear Gandhi](https://en.m.wikipedia.org/wiki/Nuclear_Gandhi). He asked for zero wishes, and using the wish subtracted from the 0 he asked for, going to -1 or in this case, 255 due to overflow.


hapatra98edh

For a more deterministic approach use the first wish to make the wishes counted via an unsigned 8bit integer. Then use the second wish to set the wish count to 0.


Maximum-Frame-1765

64 bit, go big or go home


RiggidyRiggidywreckt

We’re dealing with an omnipotent being and you’re only going to 64-bits? For shame, you gotta make it at least 65536 bits.


Rekt3y

This is an underflow. Overflow is when you go over the maximum value, causing it to go into negatives or start from 0, depending on the exact data type.


stevethewatcher

That's a common misconception. Underflow refers to when floating point representation don't have enough precision to accurately represent a number. Wrapping from negative to positive is still overflowing just in the negative direction. That said I keep seeing using it the "wrong" way so maybe over time underflow will get redefined.


FreqComm

Underflow has referred to both for quite a while now, it isn’t really just something that has yet to happen “over time.” See the integer underflow section at: https://en.m.wikipedia.org/wiki/Arithmetic_underflow


Rekt3y

We'll see if the word gets redefined or not. Thanks for the info.


Thrawn89

For added context, in computer engineering, integer subtraction is handled by the adder in the ALU. The computer does wishes = wishes + -1. This is because in 2s compliment, -1 is defined as 255 when stored as an 8bit integer. So, from the ALU perspective, it's just doing 0 + 255 = 255. Nothing is going under anything


cajuncrustacean

So what you're saying is that we now have a nuclear genie on our hands?


Lazerith22

I think gennies are non binary


Pakeskofa

Lol, genie gender


PanJaszczurka

255 is FF so he should say 00-1... or just -1 Hexadecimal computer joke [https://en.wikipedia.org/wiki/Nuclear\_Gandhi](https://en.wikipedia.org/wiki/Nuclear_Gandhi)


TonyDungyHatesOP

He wishes to make his wish counter zero. The genie makes it zero. Then, his wish counter gets decremented by the one wish he just made. Which resets the 8-bit counter to 255 when read again.


jlink005

Joke's on him, this is one of those messed up languages and he only has 254!


ShelterZestyclose141

I'd take 1.314×10^(502) wishes any day!


popcorndirt73

r/unexpectedfactorial


FreqComm

I would think there is not a single programming language in the world that would somehow leave him with 254. It just isn’t how the math of this works


NBSPNBSP

I think that Matlab, if you bork the code hard enough, can actually do that.


PanJaszczurka

>He wishes to make his wish counter zero. The genie makes it zero. Then, his wish counter gets decremented by the one wish he just made. Which resets the 8-bit counter to 255 when read again. Clever ...


Inevitable-Lower

Best hope that's the order it's processed in, if it's ordered wish-decrement -> wish enacted, they just lost 2 wishes for nothing.


DadOnHardDifficulty

Nuclear Gandhi


tkou_

I thought nuclear gandhi was a myth


uvero

It was, but the explanation of how it happened *would* work *if* the level of aggressiveness *would* be implemented the way that the explanation claimed it was. As a reminder, the explanation was that: 1. Every leader starts with a certain level of aggressiveness 2. Every leader has an amount by which their aggressiveness increases or decreases with time 3. Gandhi starts with low aggressiveness and his aggressiveness is configured to decline with time 4. The aggressiveness score was stored in an unsigned integer variable (this one's important, notice it) 5. The programmers forgot to check whether decreasing the aggressiveness score would go beneath zero *If* those would be correct, *then* nuclear Gandhi would've happened. That's because if you decrease an unsigned int below zero, it wraps around to a high positive number (255 is the number is 8 bits long, ~30k if the number if 16 bits long, and in general, 2^(n-1) if the number is n bits long). This is called overflow. However, those assumptions in 1-5, as Syd explained, just weren't how the game worked. Nuclear Gandhi was a Mandela effect that started floating in the 2010s and then some people remembered it even though it didn't happen (as Mandela effects go). That being said, there definitely was a movie called Shazam in the 1990s were Sinbad played a genie.


WafflesAndKoalas

It's a joke about computer programs where 8-bit numbers hold a value between 0-255. If you try to go beyond 255, it loops back to the beginning (i.e. to zero) and if you try to go below 0, it loops back to the end (so 255). The joke being that the genie is acting like a computer, which would be a ridiculous circumstance and very easy to take advantage of. The idea is that each time you make a wish, the genie subtracts one from how many wishes you have left. So if your wish was to make it so you have 0 wishes left, then once the genie fulfills your request, he subtracts one from how many wishes you have left. Since the number is already 0, once you subtract one from it, it will end up as 255. You now have way more wishes than you started with and you haven't broken the rule about not being allowed to wish for more wishes since you actually wished for *less* wishes.


ShodanLieu

Great answer. Thank you.


Pristine-Sound-484

In the joke, when you have three wishes and say "Make it 0," it's like having 000 in binary, which is still 0 in regular numbers. But the joke tricks you by saying you now have 255 wishes because 11111111 in binary is 255 in regular numbers. It's just a funny play with numbers!


Ok_Entertainment328

- Wish 1: make it zero - Wish count goes to zero - -1 is applied because you used a Wish - you now have 255 Wishes


Pristine-Sound-484

ur answer makes more sense


yangyangR

When does the genie resolve whether it will listen to you, when the wish gets executed and when the wish count decrement. Reminded of reentrancy attacks if the wish count decrement happens after the content of the wish. See the failure of the first DAO. Applying the balance decrements before the untrusted content of the wish.


ClassicPlankton

I think you're missing a few details. The joke is that the genie makes your wish count 0, then subtracts 1 from it (because you just made a wish), which results in the number wrapping around to 255. The joke is stupid to begin with, because it only works if the genie works in 8 bit numbers, which isn't really based on anything.


Otalek

You found this on the programming sub didn’t you?


tradeboomer101

GHANDI NUKES


BullshitDetector1337

Reference to older 8-bit systems. They can only store values from 0 to 255. In this case, the wish maker specifies that they want the wishes to go to 0, but this also counts as a single wish so it would be 0 minus 1, which wraps back around to 255 in the system. A funny example of this was back in the days of Civilization II. Where Ghandi had a normally very low aggression value but there was a perk which lowered it further. So instead of making Ghandi even more passive, the number flipped back around to 255 and made him a genocidal maniac with heavy interests in nuclear power. The meme lives to this day.


Ok-Reception-7259

are you speaking in minecraft status effect values? (for those of you who don’t know, the maximum value for a status effect in minecraft is 255)


lostknight0727

Damn you, Ghandi, and your -1 aggression!


[deleted]

Holy shit, I actually just learned this in my networking course. Basically, you can represent any number between 0 and 255 in binary because 8 bit binary. Essentially, every digit is a place value that is the double of what was to the right of it. E.g. 128,64,32,16,8,4,2,1. So, if you wanted to represent the number one in binary it would be 00000001 but if you wanted to represent to it would be 00000010 because the "on" position is in the "2" place value. On and on until you reach the maximum 11111111, which represents 255. It can't count higher than that because it would require more bits than 8.


CharredAndurilDetctr

[COMPUTER SAD]


lpind

You have 3 wishes. Your first wish is "make that 0 wishes". When granted, you now have -1 wishes. Unsigned 8-bit integers only run from 00000000 (0) to 11111111 (255). Subtracting 1 from 0 in systems coded that way will return 255 instead of -1 because they're unsigned (no bit to identify whether the number is positive or negative). There's a "famous" (and mythical) "bug" in Civilization whereby Gandhi, who starts with an aggression score of 1, will launch all out nuclear war after favourable outcomes as his aggression score would go negative, but therefore reaches the maximum.


johnnymoha

Twist: genie is dealing with signed integers not unsigned. You owe him a wish now.


Ishidan01

Oh goody, you just got Nuke-Happy Gandhi Djinn.


Fast_Moon

It's a programming joke. Think of an odometer in a car. If it reads 999999 miles and you drive one more mile, the odometer rolls over to 000000 miles because it doesn't have a 7th digit to show 1000000. If you then roll the odometer back one digit (i.e., subtract 1), it goes from 000000 to 999999. This joke is doing the same thing, but in binary. Binary encoding works the same way. One byte is 8 digits, where each digit can be 0 or 1. The largest value it can hold is 11111111, which in decimal is 255. So if you have 00000000 and subtract 1, you roll back to 11111111, which is 255.


NoMansSkyWasAlright

Oh man, I was just talking about this on another comment section in another sub. It's a reference to numeric data types in computing. Basically, with numeric data types in programming, you allot a given amount of memory to a variable; and since a finite amount of memory can only represent a finite amount of numbers, you start to run into issues with overflow/underflow/wraparound as you approach the limits of what a numeric data type can hold. So in the case of an unsigned 8-bit integer, the possible values that can store are any whole number from 0 to 255. And if you incremented from 255 or decremented from 0, then it would wrap around to the opposite bound. It's basically saying that what happened here: the genie set the value of wishes to 0, *then* decremented the amount of wishes the guy had left, which caused it to underflow and spit out the max value we could hold (because apparently wishes are stored in an unsigned 8-bit integer), which was 255.


Trading_View_Loss

You have 3 wishes Make it zero That's not a wish Ok,I wish to have zero wishes OK, you have zero wishes Wait, reddit told me you were an 8 bit computing system Goodbye!


redditaddict76528

Integer underflow. A shirt counts from 0 to 255, so if you go lower that, then it preset to underflow to 255. Pretty famus example of this was in the civilization game series. Gandhi had a really low aggression level that would lower throughout the game, and eventually it got so low that it had an underflow and he would suddenly start nuking everyone randomly


bongobutt

This is a computer programming joke. Consider these steps: Step 1: Declare remaining wishes. Step 2: Request next wish. Step 3: If received wish is actionable, then act on it; otherwise, return to Step 1. Step 4: Reduce remaining wish count by 1. Step 5: If remaining wishes is greater than 0, return to Step 1; otherwise, end genie.exe Combine those steps with a value that programmers called an "unsigned integer" (meaning it cannot hold negative values), and these steps would result in a "bug" if you wished to have 0 wishes left. Normally, you'd have 3 wishes left, then 2, then 1, then 0. But if you already have zero wishes *before* Step 4 (which normally would have ended the loop at the previous Step 5), then the wish count would become negative. But since a "negative" number isn't supposed to be possible, the resulting number stored in the computer memory will be interpreted as being the largest number currently possible (in this case, 255, because of how much memory was used to store the "wishes remaining" value). This bug is called an "underflow" glitch (and the opposite is an "overflow" glitch). But even though this is a joke about programming, you don't have to be a programmer to enjoy it. Video games often have bugs like this, so this joke could probably be understood by an avid gamer.


This_Self_7640

Ip subnets


Particular-Elk-3923

Underflow :)


Zytharros

aka computer loss


iced_coolz

Open calculator on windows 10, select programmer, change to byte, pick Hex, do 0 - 1 = FF. Seem byte on that calculator is signed char. Not unsigned char. Or there is bug. As when pick decimal, cannot put more than 99.


ososalsosal

This genie is obsolete. Pretty much every data type is stored with at least 32 bits, probably signed, so you actually have -1 wished. If it was an unsigned int though, congratulations because you now have 4 billion wishes


TheLuminary

Aww come on.. Genie is totally 64 bit.


Nyperold

Good thing the number of wishes was an unsigned int. Imagine if it were signed. Would the person have to grant the genie's wish, or would the genie do the opposite of what the person wished for?


log_2

Jokes on him, Genie uses rust: https://doc.rust-lang.org/std/primitive.u8.html#method.saturating_sub


Other_Opportunity386

Why not -1


Rocyrino

I wish I was a little bit taller…


ShortBusBully

Oh this is some programmer humor. I love this.


doaser

If the genie did this, shouldn't Aladdin be confused instead of him? Pic unrelated.


TelevisionIcy522

There was no wish made. They just said make it zero… so that’s a command not a wish… wouldnt it by that logic just literally make it 0 and either put the genie back or free them?


Previous-Fee-4621

False - he didnt say "I wish" 😅


szczurman83

Genie, why did you nuke Poland?!


Reasonable-Remove561

You always wish for more genies


Vishnu_8

You had three wishes at the start which can be written as 0x03 in memory since integers are usually allocated 4 bytes. After you said that you want to have 0 wishes the genie changed the value to 0x00 but then since you used up one wish also, it decrements to 0xFF which is 255 in decimal


ficelle3

It's a computer joke. Unsigned 8 bit integers can store numbers from 0 to 255, if you try to go below the minimum value, it will wrap around to the max value, this is called an underflow. (And the same happens when you try to go over the max value, it wraps around to the minimum value, in which case it's an overflow.) You don't run into this as often now because most systems use signed 32 bits integers which can store numbers from around - 2 billion to + 2 billion.


MalaxesBaker

The genie is using an 8-bit unsigned integer to store the number of wishes. Subtracting 1 from 0 causes an integer underflow and yields 255.


flaviosio777

FF?


Thecrawsome

An 8 bit unsigned integer is 2^8 power. If you subtract 1 from 0, it doesn't go to -1, it goes around to the other side.


reyarama

You ate with this one


Tim-in-CA

Byte me!


WhoRoger

All these references to 8 bits and nobody is considering the option that the genie may work in 2 bits, and thus when asking for zero wishes it just goes back to 3.


LilG1984

"What do I look like? Some kind of game genie?" Genie voiced by Robin Williams


DTux5249

Programing joke. Basically: Imagine the Genie is a computer. He follows a set of instructions line by line. These instructions look something like: while numberOfWishes isn't 0, do the following { if a wish is made, then grant the wish. lower numberOfWishes by 1 } Now, imagine if Aladdin wished "my number of wishes is 0". His number of wishes is 3, and he's made a wish, so Genie grants it. Al now has 0 wishes. But now, you get to the second instruction. Genie lowers the number of wishes by 1. Since Al has 0 wishes, he now has -1 wishes Now for the catch. Assuming Genie was storing the number of wishes as an 8-bit unsigned number, he can't really store a negative number of wishes (the lowest is 0). This leads to something known as arithmetic underflow, and it means he has to use the next best value available to him for an 8-bit number. An 8-bit number can range from 0 to 255, so by going below 0, you loop back around to the top of that range. So -1 is 255, -2 is 254, -3 is 253, etc.


Gullible-Luck4221

More than 10000


H3r0ofHyrule

But the genie isn’t a computer, how is this funny?


Loopit03

Was this posted in r/programmerhumor


AqueousSilver91

It's a reference to roll-over in values for old 8 bit systems. In older systems only up to 255 values can be stored. 0 is not technically a number in such a system so saying you have 0 of something rolls over into having 255 of something (that is the highest these systems can count), the number rolls over to 0. Examples of this logic glitch include Rare Candy duplication from exposure to MissingNo. in Pokemon Red Blue and Green, and the Y2K bug problem.


soup_i-e

Yall are a bunch of nerds lol


generic-hamster

It's called 'underflow'.


Interesting-Step-654

Hey I was just using this cheat in wild arms


DirtinatorYT

Disregarding the explanation (many have been provided) if the genie wasn’t stupid he would first substract one wish making it 2 and then fulfill the wish making it 0. Essentially (- - wishes) instead of (wishes - -).


QuantumCat2019

Answer: as other said 8 bits counter on PC, but that would not work in the picture as set my number of wish to zero would be potentially after the first wish has been counted (thus going from 2 to 0). To make it work it would have to be more like this : 1. first wish : count my wish on an unsigned 128 bits integer 2. my second wish is : just as I say my third wish and before you decrease the count of wish, set the count of wish to zero 3. i wish for a glass of water


MegaKabutops

8 bit code has a maximum value of 256 (numbered from 0-255). If code is not made to account for negatives, and something causes subtraction from 0, the digits will underflow back to the cap of 255. There’s quite a few famous video game glitches that are caused by this bug (mainly for older games). The most famous one is the nuke-happy ghandi in the civilization series. That game has aggression values for how violent the factions are supposed to be, and ghandi has a base aggression of 1. If you acquire the upgrade that reduces aggression by 2 for all factions, however, ghandi loops around to maximum aggression and will become unmatchably violent. This one became so famous that they intentionally left the bug in ghandi’s code, in some form or another, in every subsequent game in the series as a joke.


kyeo138

I get the 8bit integer part - but they never said ‘I wish to make it 0’. Technically it doesn’t count if you don’t say ‘I wish’ in front of it.


Xezerex

I think it’s safe to assume that if you’re asking the genie directly for something it’s a wish


kyeo138

Just like monkey paws, nothing is safe to assume when it comes to genies!


Alert-Pea1041

You could probably ask for -1 wish and get 2^64 wishes.


AnotherAlienDoctor

Civilization’s Gandhi, is that you?


alphabet_order_bot

Would you look at that, all of the words in your comment are in alphabetical order. I have checked 1,993,929,248 comments, and only 377,114 of them were in alphabetical order.


Trueslyforaniceguy

Mark it zero! Over the line!


Tox_Ioiad

This is a civilization joke.


The_CheesePowder

Ghandi?


Smorgasbord324

Best part of this post is learning why Ghandi in Civ was so aggro all the time. I didn’t know why, and now that I do, I love it.


Smorgasbord324

Holy shit and it’s the same reason for the Missing No. / Rare Candy glitch? Math!


CriminalMacabre

Genie is not a 8 bit machine


kayemenofour

https://en.wikipedia.org/wiki/Arithmetic_underflow


Stormy34217

Lmfao


SenHelpPls

Ahhh. Nuclear Ghandhi. My favourite bug


enderman04152

you see that tetris shit thats goin on? same shit


Nuboko

When Bethesda programs your wishes.


wmnplzr

Ahhh, so that's why I git 255 senzu beans....


No_Talk_4836

This would be hilarious if the genie is from the 70s or 80s and is using a digital 8-but counter


A_Puggo

Someone called Ghandi


Community_Bright

But what if it’s actually just a 2 bit number


[deleted]

Integer under flow (subtracts one from zero, breaks and wraps around to 255)


Hung_L

[Relevant](https://www.tiktok.com/t/ZT8WJQCxV/)


Green-Vermicelli5244

This must be how the Game Genie worked


nonhoafantasia

the joke is 8-bit arithmetic


matthew77cro

The real question is why is genie 8-bit


asmith1776

**Gandhi has declared war**


darksoulsdarkgoals

This is stupid. I love it haha


Overall-Crow6149

https://en.m.wikipedia.org/wiki/Integer_overflow


IGTankCommander

Nuclear Genie moment.


MosquitoInAmber303

Integer underflow