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

  • Security with Go
  • John Daniel Leon
  • 184字
  • 2021-06-30 19:06:47

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)
}
主站蜘蛛池模板: 江津市| 盐亭县| 海安县| 襄樊市| 霸州市| 龙陵县| 湘乡市| 珠海市| 伊金霍洛旗| 庆元县| 天镇县| 利津县| 临泉县| 龙陵县| 沛县| 曲阜市| 伽师县| 新乐市| 文水县| 仁化县| 达州市| 阳西县| 石门县| 开化县| 安国市| 突泉县| 西吉县| 绥滨县| 呈贡县| 绥化市| 彰化县| 固镇县| 苏尼特右旗| 朝阳市| 库车县| 淅川县| 长治县| 略阳县| 孟津县| 牙克石市| 玛多县|