data-conversions-complex-logic

Generate Zig 0.16 data conversion functions and unit tests from device register specifications.

Updated Mar 15, 2026
One-click install
npx skills add https://github.com/mohankumargupta/skills --skill data-conversions-complex-logic-mohankumargupta
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: data-conversions-complex-logic
Source: https://github.com/mohankumargupta/skills/tree/main/data-conversions-complex-logic
Command: npx skills add https://github.com/mohankumargupta/skills --skill data-conversions-complex-logic-mohankumargupta

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Translating hardware register specifications into correct, tested code is error-prone: sign extension, bit alignment, duplicate encodings, and out-of-range handling are easy to get wrong and hard to review. This Skill turns a canonical device spec into a Zig 0.16 project with tested conversion functions and a documented manifest of every encoding decision. ## Core Features & Use Cases - Spec-Driven Function Generation: Reads a canonical test specification and creates separate Zig functions for register-to-real-world conversions and complex logic such as CRC calculations, each with unit tests. - Contradiction and Edge-Case Resolution: Enforces mandatory policies for conflicting spec statements (worked-example tables win over prose formulas), duplicate encodings like sign/magnitude ±0, and explicit overflow policies (clamp, wrap, or error) per encode function. - Conversions Manifest: Produces a mandatory manifest recording each function's worked example, exact bit layout, and out-of-range policy, serving as the single source of truth for downstream skills. - Use Case: Given a temperature sensor datasheet spec, generate a Zig project where raw register values like 0x1500 decode to 21.0 °C, with tests derived from the spec's worked examples and all encoding decisions documented. ## Quick Start Create a Zig 0.16 project with tested data conversion functions from the device spec at artifacts/<device>/outputs/spec_<device>.md.

Frequently Asked Questions about data-conversions-complex-logic

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert raw register values to real-world values in Zig?▼

Create separate Zig functions for each conversion described in the device spec, covering sign extension, bit alignment, and scaling. Accompany each function with unit tests whose expected values come from the spec's worked-example tables rather than hand-computed arithmetic.

How to handle out-of-range values when encoding to fixed-width register fields?▼

Every encode function needs an explicit policy: clamp/saturate to the representable range, wrap, or return an error. Document the chosen policy in the function's doc comment and in the conversions manifest so downstream code inherits a reviewed decision.

What changed in Zig 0.16 std.testing for unit tests?▼

In Zig 0.16, std.testing.expect* functions like expectEqual and expectApproxEqRel return error unions and must be called with try, otherwise compilation fails. Additionally, std.testing.fuzz takes a *std.testing.Smith parameter in this version.

What should I do when a datasheet spec contradicts itself?▼

Treat the worked-example table as authoritative over inline prose formulas, since tests assert against those values. Record both conflicting statements and the chosen resolution in the conversions manifest, and never invent a third compromise value.

How do I handle duplicate encodings like sign/magnitude zero?▼

Decoders must canonicalize both representations (e.g. 0x00 and 0x80) to the same real-world value, while encoders pick exactly one canonical byte. Exclude the non-canonical duplicate from exhaustive round-trip tests, or a correct implementation will fail.