typst-bytefield icon indicating copy to clipboard operation
typst-bytefield copied to clipboard

Wrong bit headers with msb: left

Open JFMarten opened this issue 10 months ago • 0 comments

The bit headers seems to be broken in combination with msb: left. I used the following snippet to generate just some test cases

#import "@preview/bytefield:0.0.7": *

#let bf(bpr: 32, msb: left, length: 4, ok: true, header: "bytes") = {
  [*BPR:* #bpr; *MSB:* #msb; *Bytes:* #length; *Header*: #header; #if ok [✔] else {text(fill: red, [✘])};]
  v(-5mm)
  bytefield(bpr: bpr, msb: msb, bitheader(header), bytes(length)[#length; Bytes])
}

= Right
#bf(msb: right)
#bf(msb: right, length: 1, ok: false)
#bf(msb: right, bpr: 8, length: 1)
#bf(msb: right, bpr: 8, length: 2)
= Left
#bf()
#bf(length: 2, ok: false)
#bf(bpr: 8, length: 1)
#bf(bpr: 8, length: 2, ok: false)
#bf(bpr: 8, length: 2, header: "bounds", ok: false)

and got the following results:

Image

For example 2 i was unsure if the numbering is expected as it came out. For msb: left changing the bpr to e.g. 8 breaks multiple cases. It's particularly strange that the MSB is labeled 15.

JFMarten avatar Mar 03 '25 08:03 JFMarten