<p>I'm not aware of any rationale explicitly given by Satoshi for using sign-magnitude over another representation. It has the advantage of being able to more compactly represent some common numbers.</p>

CC BY-SA 4.0
2024-06-18T07:39:22.100Z
Thanks for your answer! However, as far as I know, isn't it a very little bit more compact to use two's complement as it doesn't have negative zero(so can represent -128 in a single byte unlike sign-magnitude)?
Hyunhum Cho
CC BY-SA 4.0
2024-06-21T18:53:04.907Z
@Hyunhum That's true, though the difference is absolutely minimal (and only relevant for negative numbers, which are rarely used anyway). Ultimately the question is guessing Satoshi's motivations, which isn't possible in a conclusive way.
Pieter Wuille
CC BY-SA 4.0
2024-06-17T08:06:15.337Z
2024-06-17T08:06:15.337Z
Antoine Poinsot
<p>Bitcoin script number encoding follows <a href="https://en.wikipedia.org/wiki/Signed_number_representations#Sign%E2%80%93magnitude" rel="nofollow noreferrer">sign-magnitude</a> according to <a href="https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#numbers" rel="nofollow noreferrer">BIP62</a>, while most of programming language uses two's complement for signed integer(i.e. Rust format hex representation of signed integer following two's complement).</p>
<p>As it's just encoding and the number of hex digit is not fixed, it might not have an advantage of two's complement for arithmetic operation, but wonder if there's an advantage of adopting sign-magnitude over two's complement.</p>

<script><encoding><bip62>
Why doesn't bitcoin script number follow two's complement?
Hyunhum Cho
# Why doesn't bitcoin script number follow two's complement?

(Asked by: username_0 on 2024-06-17)

Bitcoin script number encoding follows [sign-magnitude](https://en.wikipedia.org/wiki/Signed_number_representations#Sign%E2%80%93magnitude) according to [BIP62](https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#numbers), while most of programming language uses two's complement for signed integer(i.e. Rust format hex representation of signed integer following two's complement).

As it's just encoding and the number of hex digit is not fixed, it might not have an advantage of two's complement for arithmetic operation, but wonder if there's an advantage of adopting sign-magnitude over two's complement.

**Tags:** script, encoding, bip62


---

## 1 answers

### Answer by username_1 on 2024-06-17. Score: 3 | Accepted answer

I'm not aware of any rationale explicitly given by Satoshi for using sign-magnitude over another representation. It has the advantage of being able to more compactly represent some common numbers.

> **Comments:**
> **username_0**: Thanks for your answer! However, as far as I know, isn't it a very little bit more compact to use two's complement as it doesn't have negative zero(so can represent -128 in a single byte unlike sign-magnitude)?  
> **username_2**: @Hyunhum That's true, though the difference is absolutely minimal (and only relevant for negative numbers, which are rarely used anyway). Ultimately the question is guessing Satoshi's motivations, which isn't possible in a conclusive way.  

---

