CoolFace
Modelpublic

phanerozoic/threshold-sign-magnitude-convert

sourceHugging Facemitupdated 8mo agoView on Hugging Face
0likes9downloads
Model Card

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 = -1

Sign-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

TCDecimalSignMagnitude
0000+000
0111+707
1000-810*
1001-717
1111-111

*Note: -8 maps to -0 (magnitude overflow)

Architecture

ComponentCountNeurons
Sign extract11
Bit inverters33
Half-adder chain312
Output MUXes39

Total: 25 neurons, 71 parameters, 4 layers

Usage

python
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=3

Files

threshold-sign-magnitude-convert/
├── model.safetensors
├── create_safetensors.py
├── config.json
└── README.md

License

MIT