# Multiplicar entero.MAX_VALUE

Estoy tratando de multiplicar `integer.MAX_VALUE` (which is 2147483647) by 2. When I execute the program, it shows that `integer.MAX_VALUE` es -2.

Why is it -2?

preguntado el 01 de septiembre de 12 a las 16:09

## 2 Respuestas

Many modern computer architectures represent integers in binary as complemento de dos.

Adding 2147483647 to itself causes an overflow resulting in a -2 representation.

`````` 011111111111111111111111
+011111111111111111111111
-------------------------
111111111111111111111110
``````

From the above you can see that the sign bit (first one) is now 1, signifying a negative number, and that all other bits apart from the last are 1, together meaning a -2 in two's complement.

Respondido el 01 de Septiembre de 12 a las 19:09

32 bit integer which is signed. 0111 1111 1111 1111 1111 1111 1111 1111 *2 1111 1111 1111 1111 1111 1111 1111 1110

the first bit represents the sign. an overflow will cause the sign to change.

1111 1111 1111 1111 1111 1111 1111 1110 is -2

http://en.wikipedia.org/wiki/Integer_%28computer_science%29

Another experiment I recommend is to try it with an unsigned int (uint).

Respondido el 01 de Septiembre de 12 a las 16:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.