MCPcopy Create free account
hub / github.com/facebook/time / WriteBits

Method WriteBits

rtcm/bits.go:78–90  ·  view source on GitHub ↗

WriteBits writes n bits (1-32) from the least significant bits of val.

(val uint32, n int)

Source from the content-addressed store, hash-verified

76
77// WriteBits writes n bits (1-32) from the least significant bits of val.
78func (w *BitWriter) WriteBits(val uint32, n int) {
79 for i := n - 1; i >= 0; i-- {
80 byteIdx := w.pos / 8
81 bitIdx := 7 - (w.pos % 8)
82 for byteIdx >= len(w.data) {
83 w.data = append(w.data, 0)
84 }
85 if (val>>i)&1 == 1 {
86 w.data[byteIdx] |= 1 << bitIdx
87 }
88 w.pos++
89 }
90}
91
92// WriteSignedBits writes n bits of a signed value in two's complement.
93func (w *BitWriter) WriteSignedBits(val int32, n int) {

Callers 7

WriteSignedBitsMethod · 0.95
TestBitReaderSkipFunction · 0.95
TestBitWriterBytePaddingFunction · 0.95
EncodeMSM7Function · 0.95
AddSFRBXMethod · 0.95
encode1019Function · 0.95

Calls

no outgoing calls

Tested by 3

TestBitReaderSkipFunction · 0.76
TestBitWriterBytePaddingFunction · 0.76