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

TC Decimal Sign Magnitude
0000 +0 0 0
0111 +7 0 7
1000 -8 1 0*
1001 -7 1 7
1111 -1 1 1

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

Architecture

Component Count Neurons
Sign extract 1 1
Bit inverters 3 3
Half-adder chain 3 12
Output MUXes 3 9

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

Files

threshold-sign-magnitude-convert/
β”œβ”€β”€ model.safetensors
β”œβ”€β”€ create_safetensors.py
β”œβ”€β”€ config.json
└── README.md

License

MIT

Downloads last month
1
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Collection including phanerozoic/threshold-sign-magnitude-convert