This question already has an answer here:
bitSet := true
var bitSetVar int8
How can I assign bitSet
to bitSetVar
as 1
I can do this:
if bitSet {
bitSetVar = 1
} else {
bitSetVar = 0
}
Is this the best way?
</div>
This question already has an answer here:
bitSet := true
var bitSetVar int8
How can I assign bitSet
to bitSetVar
as 1
I can do this:
if bitSet {
bitSetVar = 1
} else {
bitSetVar = 0
}
Is this the best way?
</div>
Because the zero value for a int8
is 0
, the else branch is not necessary.
bitSet := true
var bitSetVar int8
if bitSet {
bitSetVar = 1
}
There are no conversions from bool
to integer types. The if statement is the best you can do.