Example #1
0
func (w *writer) hex(start bitgen.Line, n bitgen.Integer, end bitgen.Line) {
	if n.Width&(4-1) != 0 {
		panic(fmt.Sprintf("invalid hex width: %d", n.Width))
	}

	for i := n.Width - 4; i < n.Width; i -= 4 {
		var next bitgen.Line
		if i == 0 {
			next = end
		} else {
			next = w.ReserveLine()
		}

		w.hexDigit(start, n.Sub(i, i+4), next)

		start = next
	}
}
Example #2
0
func (w *writer) hexDigit(start bitgen.Line, n bitgen.Integer, end bitgen.Line) {
	n0, n1 := w.ReserveLine(), w.ReserveLine()
	w.Jump(start, n.Bit(3), n0, n1)

	n00, n01 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n0, n.Bit(2), n00, n01)

	n10, n11 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n1, n.Bit(2), n10, n11)

	n000, n001 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n00, n.Bit(1), n000, n001)

	n010, n011 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n01, n.Bit(1), n010, n011)

	n100, n101 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n10, n.Bit(1), n100, n101)

	n110, n111 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n11, n.Bit(1), n110, n111)

	n0000, n0001 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n000, n.Bit(0), n0000, n0001)

	n0010, n0011 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n001, n.Bit(0), n0010, n0011)

	n0100, n0101 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n010, n.Bit(0), n0100, n0101)

	n0110, n0111 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n011, n.Bit(0), n0110, n0111)

	n1000, n1001 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n100, n.Bit(0), n1000, n1001)

	n1010, n1011 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n101, n.Bit(0), n1010, n1011)

	n1100, n1101 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n110, n.Bit(0), n1100, n1101)

	n1110, n1111 := w.ReserveLine(), w.ReserveLine()
	w.Jump(n111, n.Bit(0), n1110, n1111)

	w.Print(n0000, '0', end)
	w.Print(n0001, '1', end)
	w.Print(n0010, '2', end)
	w.Print(n0011, '3', end)
	w.Print(n0100, '4', end)
	w.Print(n0101, '5', end)
	w.Print(n0110, '6', end)
	w.Print(n0111, '7', end)
	w.Print(n1000, '8', end)
	w.Print(n1001, '9', end)
	w.Print(n1010, 'A', end)
	w.Print(n1011, 'B', end)
	w.Print(n1100, 'C', end)
	w.Print(n1101, 'D', end)
	w.Print(n1110, 'E', end)
	w.Print(n1111, 'F', end)
}