官术网_书友最值得收藏!

Other numeric types

Go also provides a complex number for advanced mathematical applications, and a few aliases for conveniences:

  • complex64: Complex number with float32 real and imaginary parts
  • complex128: Complex number with float64 real and imaginary parts
  • byte: Alias for uint8
  • rune: Alias for int32

You can define numbers in the decimal, octal, or hexadecimal format. Decimal or base-ten numbers need no prefix. Octal or base-eight numbers should be prefixed with a zero. Hexadecimal or base-sixteen numbers should be prefixed with a zero and an x.

You can read more about the octal numeral system at https://en.wikipedia.org/wiki/Octal, decimal at https://en.wikipedia.org/wiki/Decimal, and hexadecimal at https://en.wikipedia.org/wiki/Hexadecimal.

Note that numbers are stored as integers, and there are no differences between them except for how they are formatted in the source code for the human. Octal and hexadecimal can be useful when working with binary data. Here is a short example of how to define integers:

package main

import "fmt"

func main() {
// Decimal for 15
number0 := 15

// Octal for 15
number1 := 017
// Hexadecimal for 15
number2 := 0x0F

fmt.Println(number0, number1, number2)
}
主站蜘蛛池模板: 武冈市| 武汉市| 雷州市| 水城县| 嵊泗县| 锡林郭勒盟| 喀什市| 平乡县| 会昌县| 谷城县| 桦川县| 长垣县| 禄丰县| 喀什市| 孟津县| 同仁县| 黔西县| 晋州市| 汪清县| 腾冲县| 自治县| 融水| 霸州市| 龙南县| 固原市| 浑源县| 嘉黎县| 吴堡县| 绥棱县| 平湖市| 崇仁县| 孙吴县| 济源市| 双城市| 松原市| 龙门县| 铁岭县| 舞钢市| 张家界市| 宾川县| 阿克陶县|