Go Integers: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 21: Line 21:
=Conversion of a <tt>byte</tt> to <tt>string</tt>=
=Conversion of a <tt>byte</tt> to <tt>string</tt>=


<font color=red>'''TODO'''</font>
Conversion of a <tt>string</tt> to <tt>byte</tt>s:
 
<pre>
bytes := []byte("test")
</pre>
 
Conversion of <tt>byte</tt>s to <tt>string</tt>:
 
<pre>
str := string([]byte{'t', 'e', 's', 't'})
</pre>


=Integer Literals=
=Integer Literals=

Revision as of 21:38, 30 March 2016

Internal

Overview

Integers are designated by the following pre-declared type identifiers:

  • Unsigned integers: uint8 (or byte), uint16, uint32 (or rune), uint64.
  • Signed integers: int8, int16, int32, int64.
  • Machine-dependent integers: uint, int and uintptr.

When a regular integer is needed in the program, int should be the default.

byte

byte is unsigned int represented on a byte (uint8).

Indexing operator [] applied to strings return bytes.

Conversion of a byte to string

Conversion of a string to bytes:

bytes := []byte("test")

Conversion of bytes to string:

str := string([]byte{'t', 'e', 's', 't'})

Integer Literals