phanerozoic/threshold-sign-magnitude-convert
09
threshold-sign-magnitude-convert
Converts 4-bit two's complement to sign-magnitude representation.
Circuit
TC[3:0] ──► Convert ──┬──► sign (0=positive, 1=negative)
└──► mag[2:0] (magnitude 0-7)Representations
Two's Complement (4-bit): Range -8 to +7
0000 = +0 1000 = -8
0111 = +7 1111 = -1Sign-Magnitude: sign bit + 3-bit magnitude
+0 to +7 (sign=0)
-0 to -7 (sign=1)Algorithm
If TC >= 0 (MSB = 0):
sign = 0
magnitude = TC[2:0]
If TC < 0 (MSB = 1):
sign = 1
magnitude = (-TC)[2:0] = (~TC + 1)[2:0]Conversion Table
*Note: -8 maps to -0 (magnitude overflow)
Architecture
Total: 25 neurons, 71 parameters, 4 layers
Usage
from safetensors.torch import load_file
w = load_file('model.safetensors')
# Two's complement -5 (1011) → Sign=1, Magnitude=5
# Two's complement +3 (0011) → Sign=0, Magnitude=3Files
threshold-sign-magnitude-convert/
├── model.safetensors
├── create_safetensors.py
├── config.json
└── README.mdLicense
MIT
