# Simple hexadecimal to 2s complement question

From 2.5.1 in this paper, how is

$p$ = FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFFFF 00000000 00000000 FFFFFFFF

= $2^{384} − 2^{128} − 2^{96} + 2^{32} − 1$

derived?

• What are you asking ? The conversion ? If so that's just hexadecimal representation of a positive number (there is no two's complement) – Ruggero Jan 4 '18 at 12:52
• Using big endian representation, of course. You don't have to derive anything: WolframAlpha al rescate. – Maarten Bodewes Jan 4 '18 at 16:08

## 1 Answer

To have a signed 2-complement representation then you have to left pad the value with a single 00 valued byte. Generally API's will already view hexadecimals as positive unless they are preceded with a minus sign.

E.g. in Java:

// read value from string
BigInteger x = new BigInteger("FF...FF");
// signed byte representation, with additional zero valued byte to the left
byte[] encX = x.toByteArray();