11-bitShiftingUint64ToInt

command
v0.0.0-...-9882766 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

The gimmick here is that, unique among go's arithmetic-ish operators, << does not require that its parameters have the same type. It rather requires that the right operand is an unsigned integer type.

It can't require that they be the same type, because it has to be unsigned, and you have to be able to shift ints. So 1 << uint64(x) is an expression shifting a constant left by x, but nothing in the expression constrains the type of the constant. A constant which does not have its type constrained and could be an int is an int. if you had this in a func returning (res uint64), and did res = (1 << ui) - 1, you'd get a uint64.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL