content: explain shift operator in constants example
This addresses concerns raised in
https://go-review.googlesource.com/#/c/19325/
The literal number 1267650600228229401496703205376 is potentially
hard read. 1,267,650,600,228,229,401,496,703,205,376 was suggested
as an alternative.
The == operator has not yet been used in an example in the tour,
and so using it could potentially also confuse people.
Additionally it seems useful to hint at what << and >> mean, rather
than glossing over it entirely.
Change-Id: I89652eea138a91f3da5b7629b0edfaa96dcdbc23
Reviewed-on: https://go-review.googlesource.com/19370
Reviewed-by: Andrew Gerrand <adg@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ralph Corderoy <ralph@inputplus.co.uk>
diff --git a/content/basics/numeric-constants.go b/content/basics/numeric-constants.go
index 97d5155..59784b5 100644
--- a/content/basics/numeric-constants.go
+++ b/content/basics/numeric-constants.go
@@ -5,8 +5,11 @@
import "fmt"
const (
- Big = 1 << 100 // == 1267650600228229401496703205376
- Small = Big >> 99 // == 2
+ // Create a huge number by shifting a 1 bit left 100 places.
+ // In other words, the binary number that is 1 followed by 100 zeroes.
+ Big = 1 << 100
+ // Shift it right again 99 places, so we end up with 1<<1, or 2.
+ Small = Big >> 99
)
func needInt(x int) int { return x*10 + 1 }