<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.explainxkcd.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=2001%3A4C4E%3A1C01%3AEB00%3A4EEE%3A3DF5%3AFF18%3AAD2D</id>
		<title>explain xkcd - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://www.explainxkcd.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=2001%3A4C4E%3A1C01%3AEB00%3A4EEE%3A3DF5%3AFF18%3AAD2D"/>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php/Special:Contributions/2001:4C4E:1C01:EB00:4EEE:3DF5:FF18:AD2D"/>
		<updated>2026-04-05T16:56:40Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=571:_Can%27t_Sleep&amp;diff=409597</id>
		<title>571: Can't Sleep</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=571:_Can%27t_Sleep&amp;diff=409597"/>
				<updated>2026-04-04T06:05:04Z</updated>
		
		<summary type="html">&lt;p&gt;2001:4C4E:1C01:EB00:4EEE:3DF5:FF18:AD2D: /* Explanation */ s is the correct abbr&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 571&lt;br /&gt;
| date      = April 20, 2009&lt;br /&gt;
| title     = Can't Sleep&lt;br /&gt;
| image     = cant sleep.png&lt;br /&gt;
| titletext = If androids someday DO dream of electric sheep, don't forget to declare sheepCount as a long int.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
[[Cueball]] is in bed and is having trouble sleeping. He tries the old standby of {{w|counting sheep}} as they jump over a fence, but upon reaching 32,767 sheep, 65535 sheep jump back over the fence and start counting up again from -32,768. This is a reference to an integer overflow, when an increasing amount (sheep in this case) suddenly overflows and shows up as a negative value. This is because when a whole number or integer is represented in a digital form, such as on a computer, the number's range is limited by the amount of space used to store it. When the greatest possible number given the storage space is exceeded, an arithmetic overflow occurs, which may result (depending on the used language among other things) in starting over at the least possible number given the storage space, similar to a car's odometer. Imagine an odometer with six digits reaching 999999. Upon driving one more mile or km, the digits will roll back over to 000000. The negative number comes from half of the possible values representing positive numbers, and half representing negative numbers. For the odometer, imagine numbers on or over 500000 represented negative numbers (the remainder of the number, minus the 500000, offset by 500000 in the negative direction), so 500000 represented -500000, 500001 represented -499999, etc, until 999999 represents -1 (then flips over to 000000 to be true zero again). Causing or failing to prevent integer overflow is a common mistake by programmers that may have software security consequences. Some languages like C/C++ even leaves the signed integer overflow ''undefined behavior'', it may or may not wrap to the beginning, the instruction can be ignored or may cause the software to crash.&lt;br /&gt;
&lt;br /&gt;
In this case, the least and greatest possible numbers are -32,768 and 32,767, which implies that Cueball's brain would only be 16-bit. In addition, it's clear that the number is designated as a signed number, meaning that it can be either positive or negative.&lt;br /&gt;
&lt;br /&gt;
However, even if Cueball had this limitation, it would never actually pose a problem. By 32,767 sheep, at a rate of one sheep per second, Cueball has been counting for 9.101 hours (or about 9 hours 6 minutes). This would signify that he has extreme insomnia and probably needs treatment, and also that he has spent the entire night counting, and therefore would just get up and start the day rather than count sheep all over again from -32,768.&lt;br /&gt;
&lt;br /&gt;
The title text refers to the 1968 Philip K. Dick science fiction novel ''{{w|Do Androids Dream of Electric Sheep?}}'', which was adapted into the perhaps more widely known Ridley Scott directed 1982 film ''Blade Runner''. The implication is that if we ever do create androids that dream of electric sheep, we should make sure to give them sufficient storage space to store numbers large enough such that an arithmetic overflow will be far less likely to occur, even if they count for a long time. A &amp;quot;long int&amp;quot; depends on machine architecture, but it typically consists of four bytes rather than two, so instead of being limited to a range from -32,768 to 32,767 the number will be capable of storing numbers from -2,147,483,648 to 2,147,483,647, which would take 68.1 years to exhaust (at the rate of 1 sheep/s). &amp;quot;sheepCount&amp;quot; is a possible name for a variable to be used in a computer program. Declaring a variable tells the computer that it should allocate a portion of memory to be associated with the variable name given. No spaces are used because variables cannot contain spaces, for a reason that would take a little too long to properly explain here.&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
:[Cueball is in bed, presumably trying to sleep. The top of each panel is a thought bubble showing sheep leaping over a fence and Cueball's counting and the sheeps baaing is written above the sheeps. Two sheep are jumping from left to right in the first panel.]&lt;br /&gt;
:1... 2...&lt;br /&gt;
:Sheep: Baaa&lt;br /&gt;
&lt;br /&gt;
:[Two sheep are jumping from left to right. Cueball is holding his pillow.]&lt;br /&gt;
:... 1,306... 1,307...&lt;br /&gt;
:Sheep: Baaa&lt;br /&gt;
&lt;br /&gt;
:[A whole flock of sheep (nine visible) is jumping over the fence from right to left; the first and last sheep is cut off at the edge of the frame. Cueball is now sitting up looking up at his thought bubble.]&lt;br /&gt;
:... 32,767 ...-32,768...&lt;br /&gt;
:Sheep: Baaa baaa baaaa baaa ba&lt;br /&gt;
:Cueball: ?&lt;br /&gt;
&lt;br /&gt;
:[Two sheep are again jumping from left to right. Cueball is holding his pillow over his head.]&lt;br /&gt;
:...-32,767... -32,766...&lt;br /&gt;
:Sheep: Baaa&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Animals]]&lt;br /&gt;
[[Category:Dreams]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>2001:4C4E:1C01:EB00:4EEE:3DF5:FF18:AD2D</name></author>	</entry>

	</feed>