This is a creation in Article, where the information may have evolved or changed. # The basic data type of the go language the data type of the #***go language is divided into four main types: base type (number, String, Boolean type), compound type (array, struct), reference type (pointer, slice, dictionary, function and channel), interface type </font>***# #整型Go The integer definition type of the language has a symbolic type of **int8,int16,int32,int64**, unsigned type **uint8,uint16,uint32,uint64. int and uint correspond to different bits for the respective hardware platform. and uintptr**<table class= "table table-bordered table-striped table-condensed" > <tr> <td> type </td ><td> unsigned </td> <td>bit </td> </tr> <tr> <td>int8</td><td> yes</td> <td>8</td> </tr> <tr> <td>int16</td><td>yes</td> <td>16</td> </tr> <tr> <td>int32</td><td>yes</td> <td>32< /TD> </tr> <tr> <td>int64</td><td>yes</td> <td>64</td> </tr > <tr> <td>uint8</td><td>no</td> <td>8</td> </tr> <tr> < Td>uint16</td><td>no</td> <td>16</td> </tr> <tr> <td>uint32</td><td>no</td> <td>32</td> </tr> <tr > <td>uint64</td><td>no</td> <td>64</td> </tr> <tr> <td> Int</td><td>yes</td> <td> equals the number of CPU bits </td> </tr> <tr> <td>uint</td ><td>no</td> <td> equals CPU number of bits </td> </tr> <tr> <td>byte</td><td >no</td> <td> equals uint8</td> </tr> <tr> <td>rune</td><td>yes</ Td> <td> equivalent to int32</td> </tr> <tr> <td>uintptr</td><td>no</td> The bit operators for <td>-</td> </tr></table>go languages have the following:& bitwise operations and | Bitwise operation or ^ bitwise operation XOR &^ bit emptying (and not) << left shift >> right shift most of these operators are no different from the C language, here &^ the operator is the combination of & and ^ x &^ y Here It means that Y is 1 bits are 0, then the rest is the same as X. That is, the ^y operation is performed first and then &x. # #浮点型1. Floating-point numbers indicate that the go language defines two types float32 and float64, where float32 is equivalent to the C-language float type, float64, etc.Double type for the C language. Here to popularize float in memory storage mode float Total 32 bits, 4 bytes from the highest to the lowest is the 31st, 30, 、......、 0 bits 31 bits is the sign bit, 1 indicates that the number is negative, 0 instead. 30-23 bits, altogether 8 digits are digits. 22-0 bits, altogether 23 bits are the trailing digits. The precision of float is determined by the number of bits in the mantissa. Floating-point numbers are stored in memory by scientific notation, and the integer part is always an implied "1", because it is invariant and therefore cannot affect precision. float:2^23 = 8388608, a total of seven bits, which means that there can be up to 7 significant digits, but it is guaranteed to be 6 bits, which is the precision of float is 6~7 digits. Do not understand can refer to [http://blog.csdn.net/flowaway_/article/details/41597727] (http://blog.csdn.net/flowaway_/article/ details/41597727) then the Go Bible code: var f float32 = 16777216//1 << FMT. Println (f = = f+1)//"true"! why F = = f+1, in fact, is the problem of precision, we can test the results of f+3 and f+4 should be the same, for the first bit to discard (more than 23 bits of the first bit if 1 is to carry to the front). For floating-point comparisons, because they are imprecise, you cannot use = =, you can use the following code to import the "math" func checkqual (F1, F2, p float64) bool {return math. Fdim (F1, F2) < p}p are user-defined precision, such as: 0.000001***# #复数复数由两部分组成, Real and Imaginary (imag). The Go language provides complex64 and complex128 two accuracy. The representation of the plural: var x complex64x = 4 + 4iy: = 4 + 4iz: = Complex here x is the complex64 type, y,z belongs to the complex128 type. For complex numbers, you can get the real and imaginary parts of a complex number by using the real (x) and Imag (x) built into the go language. # #布尔类型布尔类型和和C语言的没什么区别关键字bool, you can assign a value of true and false. There are no other things to tell. # #字符串和Byte切片字符串在任何语言里面都是A very useful thing. The go language is a string type that supports native literals directly. The operation of the string in the go language feels much like the operation in Python, see the following string manipulation code: Func Stringfunc (S string) {Fmt. Printf ("%c", s[0])//subscript operation and traditional C as var f string = ", Wenxuwan" s = s + F//String connection, can be directly + link two string fmt. Println (S[0:4])//truncate operation, print 0-3 of the following table string FMT. Println (Len (s))///print the length of the string}var str string = "Hello,world" Stringfunc (str) for Chinese characters, if you want to get to Chinese characters, you can first convert the string to a rune array, Get Unicode in Chinese, and then convert Unicode to characters with a string. # #常量-The 1 constant keyword is the same as the C language, which is const: const i = 3.1415926const supports batch declaration of const (a = 10BC =20d) batch declaration except the first one must be assigned, others can be omitted. If you print the value of a,b,c,d, the result is 10,10,20,20. Keep the same value as above. 2 in this case, the const batch declaration does not have much effect, so we need to introduce iota (constant generator), which is the same as the enum in other languages, after the const (first = Iotasecondthird fourth) output, The result should be 0,1,2,3. What would the result be if the code was the following const (first = Iotasecondthird = 10fourth)? If so, what is the result? Const (first = Iotasecondthird = 10fourth = Iota) You can use this to feel the iota. There is also a way to use the const (first = 1 << Iotasecondthirdfourth) Results everyone test it. 214 reads
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service