File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,37 @@ PyVSC also provides operator overloading for `randobj`-decorated classes that
151151allows the value of class attributes to be accessed directly.
152152
153153
154+ Converting Bit Patterns to Values
155+ ==================================
156+
157+ When interfacing with hardware (DUT), bit patterns often need to be interpreted
158+ as signed or unsigned values. PyVSC provides the `ValueInt.from_bits() ` class method
159+ to convert bit patterns to properly-interpreted integer values:
160+
161+ .. code-block :: python3
162+
163+ import vsc
164+
165+ # Convert unsigned 8-bit value
166+ unsigned_val = vsc.ValueInt.from_bits(0xFF, width=8, signed=False)
167+ # Result: 255
168+
169+ # Convert signed 8-bit value
170+ signed_val = vsc.ValueInt.from_bits(0xFF, width=8, signed=True)
171+ # Result: -1
172+
173+ # Practical example: reading from DUT
174+ dut_register_value = 0xFFFFFFF0
175+ python_value = vsc.ValueInt.from_bits(dut_register_value, width=32, signed=True)
176+ # Result: -16
177+
178+ The method properly:
179+
180+ * Masks the value to the specified bit width
181+ * Detects the sign bit (MSB) when `signed=True `
182+ * Converts negative values using two's complement representation
183+
184+
154185List-type Attributes
155186================================
156187
You can’t perform that action at this time.
0 commit comments