#K65647. Hexadecimal to Signed 32-bit Decimal Conversion

    ID: 32244 Type: Default 1000ms 256MiB

Hexadecimal to Signed 32-bit Decimal Conversion

Hexadecimal to Signed 32-bit Decimal Conversion

You are given an 8-character hexadecimal string representing a signed 32-bit integer in two's complement form. Your task is to convert the hexadecimal string into its corresponding signed decimal value.

The conversion is defined as follows:

Let \( N \) be the integer value of the hexadecimal string when interpreted as an unsigned 32-bit integer. If \( N \geq 2^{31} \), then the result is \( N - 2^{32} \); otherwise, the result is \( N \). In other words:

\[ \text{result} = \begin{cases} N, & \text{if } N < 2^{31} \\ N - 2^{32}, & \text{if } N \geq 2^{31} \end{cases} \]

In addition, the input will consist of multiple lines provided over stdin. Process each line until you encounter the string "END". For each hexadecimal string encountered before the termination signal, output the corresponding decimal value on a new line using stdout.

inputFormat

The input consists of multiple lines. Each line contains an 8-character hexadecimal string. The end of input is indicated by a line containing only "END" (without quotes). You should read from stdin.

Examples:

FFFFFFFF
00000001
70000000
80000000
END

outputFormat

For each hexadecimal string (except the terminating "END"), output its corresponding signed decimal value on a separate line to stdout.

For the sample input above, the output should be:

-1
1
1879048192
-2147483648
## sample
FFFFFFFF
00000001
70000000
80000000
END
-1

1 1879048192 -2147483648

</p>