Difference between revisions of "571: Can't Sleep"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
(Explanation: added third paragraph)
(6 intermediate revisions by 4 users not shown)
Line 4: Line 4:
 
| title    = Can't Sleep
 
| title    = Can't Sleep
 
| image    = cant sleep.png
 
| image    = cant sleep.png
| imagesize =
 
 
| titletext = If androids someday DO dream of electric sheep, don't forget to declare sheepCount as a long int.
 
| titletext = If androids someday DO dream of electric sheep, don't forget to declare sheepCount as a long int.
 
}}
 
}}
  
== Explanation ==
+
==Explanation==
In this comic, [[Cueball]] is in bed and is having trouble sleeping. He tries the old standby of counting sheep as they jump over a fence, but upon reaching 32,767 sheep, the sheep all jump back over the fence and start counting up again from -32,768. This is because when an integral number 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 results in starting over at the least possible number given the storage space. This is not at all unlike a car's odometer. Imagine an odometer with six digits reaching 999999 miles. Upon driving one more mile, the digits will roll back over to 000000.
+
[[Cueball]] is in bed and is having trouble sleeping. He tries the old standby of counting sheep as they jump over a fence, but upon reaching 32,767 sheep, the sheep all jump back over the fence and start counting up again from -32,768. 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 results in starting over at the least possible number given the storage space. This is not at all unlike a car's odometer. Imagine an odometer with six digits reaching 999999 miles. Upon driving one more mile, the digits will roll back over to 000000.
  
 
In this case, the least and greatest possible numbers are -32,768 and 32,767, which implies that the storage space used would be two bytes. In addition, it's clear that the number is designated as a signed number, meaning that it can be either positive or negative.
 
In this case, the least and greatest possible numbers are -32,768 and 32,767, which implies that the storage space used would be two bytes. In addition, it's clear that the number is designated as a signed number, meaning that it can be either positive or negative.
  
The image text refers to the 1968 Philip K. Dick science fiction novel ''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 "long int" 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. "sheepCount" 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. For those who might be unfamiliar with common programming practices, "sheepCount" is named using what is commonly referred to as CamelCase, meaning that all words in the name ("sheep" and "count") are pushed together and the first letter of every word after the first is capitalized. This is one of several common approaches to naming variables in computer programming.
+
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 over nine hours. 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. Moreover, according to an experiment conducted by researchers at Oxford University, {{w|Counting sheep|counting sheep is actually an inferior means of inducing sleep}}.
  
{{Comic discussion}}
+
The title text refers to the 1968 Philip K. Dick science fiction novel ''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 "long int" 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. "sheepCount" 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. For those who might be unfamiliar with common programming practices, "sheepCount" is named using what is commonly referred to as CamelCase, meaning that all words in the name ("sheep" and "count") are pushed together and the first letter of every word after the first is capitalized. This is one of several common approaches to naming variables in computer programming.
 +
 
 +
==Transcript==
 +
:[Cueball is in bed, presumably trying to sleep. The top of each panel is a thought bubble showing sheep leaping over a fence.]
 +
:1... 2...
 +
:baaa
 +
:[Two sheep are jumping from left to right.]
 +
 
 +
:... 1,306... 1,307...
 +
:baaa
 +
:[Two sheep are jumping from left to right. The would-be sleeper is holding his pillow.]
 +
 
 +
:... 32,767... -32,768...
 +
:''baaa baaa baaa baaa baaa''
 +
:[A whole flock of sheep is jumping over the fence from right to left. The would-be sleeper is sitting up.]
 +
:Sleeper: ?
 +
 
 +
:... -32,767... -32,766...
 +
:baaa
 +
:[Two sheep are jumping from left to right. The would-be sleeper is holding his pillow over his head.]
 +
 
 +
{{comic discussion}}
 
[[Category:Comics featuring Cueball]]
 
[[Category:Comics featuring Cueball]]

Revision as of 23:00, 20 January 2014

Can't Sleep
If androids someday DO dream of electric sheep, don't forget to declare sheepCount as a long int.
Title text: If androids someday DO dream of electric sheep, don't forget to declare sheepCount as a long int.

Explanation

Cueball is in bed and is having trouble sleeping. He tries the old standby of counting sheep as they jump over a fence, but upon reaching 32,767 sheep, the sheep all jump back over the fence and start counting up again from -32,768. 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 results in starting over at the least possible number given the storage space. This is not at all unlike a car's odometer. Imagine an odometer with six digits reaching 999999 miles. Upon driving one more mile, the digits will roll back over to 000000.

In this case, the least and greatest possible numbers are -32,768 and 32,767, which implies that the storage space used would be two bytes. In addition, it's clear that the number is designated as a signed number, meaning that it can be either positive or negative.

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 over nine hours. 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. Moreover, according to an experiment conducted by researchers at Oxford University, counting sheep is actually an inferior means of inducing sleep.

The title text refers to the 1968 Philip K. Dick science fiction novel 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 "long int" 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. "sheepCount" 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. For those who might be unfamiliar with common programming practices, "sheepCount" is named using what is commonly referred to as CamelCase, meaning that all words in the name ("sheep" and "count") are pushed together and the first letter of every word after the first is capitalized. This is one of several common approaches to naming variables in computer programming.

Transcript

[Cueball is in bed, presumably trying to sleep. The top of each panel is a thought bubble showing sheep leaping over a fence.]
1... 2...
baaa
[Two sheep are jumping from left to right.]
... 1,306... 1,307...
baaa
[Two sheep are jumping from left to right. The would-be sleeper is holding his pillow.]
... 32,767... -32,768...
baaa baaa baaa baaa baaa
[A whole flock of sheep is jumping over the fence from right to left. The would-be sleeper is sitting up.]
Sleeper: ?
... -32,767... -32,766...
baaa
[Two sheep are jumping from left to right. The would-be sleeper is holding his pillow over his head.]


comment.png add a comment! ⋅ comment.png add a topic (use sparingly)! ⋅ Icons-mini-action refresh blue.gif refresh comments!

Discussion

The odometer analogy needs more explanation because of the difference between signed vs. unsigned integers. This assumes the analogy should stay here. --Smartin (talk) 05:02, 4 January 2013 (UTC)

I replaced the phrase "integral number" with "integer", because "integral" is an overloaded term in math, while "integer" always means a signed whole number, and is introduced in grade school arithmetic. --MisterSpike (talk) 15:39, 19 August 2013 (UTC)

While semi relevent, I don't think it is necessary to have an explanation of variable naming convention in the title text explanation. Definately note that sheepCount is a variable, but to go into detail on naming convention I think it just bloats the paragraph.. --Pudder (talk) 08:09, 29 September 2014 (UTC)

Since I did not know about it I found it relevant - else I might have questioned the funny capitalisation. --Kynde (talk) 18:12, 14 October 2014 (UTC)
I agree with Kynde... the purpose of explainxkcd is to explain things in the comic that seem obvious/everyday to people with particular knowledge in the areas covered by Randall's joke, but which are not obvious to those whose areas of knowledge do not overlap with Randall in that particular way, so this is exactly the sort of thing that may need an explanation. One of the hardest things in pedagogy seems to be getting an understanding of what it is that other people aren't going to understand. 108.162.249.155 01:42, 9 March 2016 (UTC)

If androids indeed are going to dream of electric sheep, please declare sheepCount as long long unsigned. Signed overflow is undefined and value isn't going to be negative either way. 162.158.203.25 18:00, 20 December 2020 (UTC)

The original comic had it that way. Though cool trivia.

I feel the explanation is missing something. When the integer overflow happens Cueball seems genuinely surprised and confused - he actually sits up in spite of him trying to sleep. It also looks like that in the second and following panels he is starting to "hear" the sheep bleating. And 64K sheep in a stampede are LOUD! And in the last panel, he holds his pillow over his head in a futile attempt to block out the sheep continuing to bleat. Nirdavo (talk) 11:40, 30 May 2023 (UTC)