Something about this makes me laugh
I know of no bit addressable computers, ever, other than the Intel
8051 which allows 16 bytes of bit addressable memory, and allows bit
access in registers, but that is a rare and slight exception to a
universal truth. Bytes are as good as it gets
I would express it as clearly as possible...I.e., use booleans. Let the compiler pack it if it wishes; nothing prevents it.
Except in extremely rare cases, especially on modern computers, I would advise always erring on the side of clarity.
Thomas
--
I would express it as clearly as possible...I.e., use booleans. Let the compiler pack it if it wishes; nothing prevents it.
type BitField struct {
data uint16
}
func (b *BitField) Get(bitnum uint) bool {
return ((b.data & uint16(1<<bitnum)) != 0)
}
//This is not how this function should be written, I just don't feel
much like thinking today.
func (b *BitField) Set(bitnum uint, value bool) {
if value {
b.data = b.data | uint16(1<<bitnum)
} else {
if b.Get(bitnum) {
b.data = b.data ^ uint16(1<<bitnum)