2

Bitcoin script number encoding follows sign-magnitude according to BIP62, 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.

1 Answer 1

3

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.

2
  • 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
    Commented Jun 18 at 7:39
  • 1
    @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. Commented Jun 21 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.