Created
September 11, 2024 08:07
-
-
Save CarsonSlovoka/02af739c677084887be76467c756d7ef to your computer and use it in GitHub Desktop.
demo int range
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func Example_int8_range() { | |
for _, val := range []byte{ | |
0b1000_0000, | |
0b1000_0001, | |
// ... | |
0b1111_1111, // 0xff | |
0, | |
1, | |
// ... | |
0b0111_1111, | |
} { | |
fmt.Println(int8(val)) | |
} | |
// Output: | |
// -128 | |
// -127 | |
// -1 | |
// 0 | |
// 1 | |
// 127 | |
} | |
func Example_int16_range() { | |
for _, val := range []uint16{ | |
0b1000_0000_0000_0000, // -32768 | |
0x80_01, // -32767 | |
//... | |
0, | |
0b0111_1111_1111_1110, | |
0x7f_ff, // 32767 | |
} { | |
fmt.Println(int16(val)) | |
} | |
// Output: | |
// -32768 | |
// -32767 | |
// 0 | |
// 32766 | |
// 32767 | |
} | |
func Example_int32_range() { | |
for _, val := range []uint32{ | |
0x80_00_00_00, | |
//... | |
0x7f_ff_ff_ff, | |
} { | |
fmt.Println(int32(val)) | |
} | |
// Output: | |
// -2147483648 | |
// 2147483647 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment