DEV Community

technonotes-hacker
technonotes-hacker

Posted on

golang - 2

TYPES

Image description

  • Variable --> to store value.

Image description

  • strongly typed language.

Image description

INT

  • These are used to declare INTEGER values.

  • upending two string in INT

Image description

Image description

  • Testing with Negative values

Image description

FLOAT

Image description

Image description

Image description

STRING

Image description

Image description

COMPLEX

  • It provides the real and imaginary value.
package main
import (
    "fmt"
)
func main() {
    var i complex64 = 2
    fmt.Println(i)
}
Enter fullscreen mode Exit fullscreen mode

Image description

BOOLEAN

  • Default value is FALSE.
package main
import (
    "fmt"
)
func main() {
    var i bool
    fmt.Println(i)
}
Enter fullscreen mode Exit fullscreen mode

Image description

  • Where it's used ? We can test with Condition.
package main
import (
    "fmt"
)
func main() {
    var i bool = 4 > 2
    fmt.Println(i)
}
Enter fullscreen mode Exit fullscreen mode

Image description

CONSTANT

  • You can define , and it can't be changed.

TYPE CONVERSION

  • It can convert from one type to another type.

Notes

  1. 1 byte = 8 bit ( high bit will be allocated to --> signature , 2 power 7 = 0 to 127 --> it accepts , range = -127 to +127 ) Eg., var i int8
  2. uint --> Reservation will be ignored. So 0 to 128 , also negative value will not be assigned. --> unsigned Integer
  3. 1 byte = uint8
  4. rune = int32
  5. Typed system is important because of the allocation of the memory.
  6. Eg., Bank Balance can be negative, if you take loan && The element with the lowest freezing point is helium, which freezes at a temperature of approximately -272.2 degrees.
  7. The Two’s Complement has unaltered positive numbers just like Sign-and-Magnitude and One’s Complement methods. The negative number is obtained by first determining the one’s complement of the relevant positive number and then adding “1” to it. The range of numbers is -128 to 0 to +127 and includes only one zero in the range.

Reference & Important Sites

https://go.dev/tour/basics/1
https://forums.tamillinuxcommunity.org/t/lets-learn-golang/1725/2
https://gitlab.com/mohan43u/letslearngolangdocs/-/blob/master/week0.org
https://go.dev/tour/list

Top comments (2)

Collapse
 
sivaraam profile image
Kaartic Sivaraam

That's some good notes from the Golang session. Just a suggestion, it would be great if you start the post with relevant context so that anyone who lacks context could easily understand ehat this post is about 🙂

Two things I observed:

1 byte = 8 bit ( high bit will be allocated to --> signature , 2 power 7 = 0 to 127 --> it accepts , range = -127 to +127 ) Eg., var i int8

The range is -128 to +127 as you mention elsewhere in the post.

uint --> Reservation will be ignored. So 0 to 128 , also negative value will not be assigned. --> unsigned Integer

Since the reservation is ignored, the range of uint8 goes from 0 to (2^8 - 1) i.e., 0 to 255

Collapse
 
technonotes profile image
technonotes-hacker

Sure , will take it up in upcoming posts .