A
A
Arsen002020-12-01 12:15:01
C++ / C#
Arsen00, 2020-12-01 12:15:01

Why is (unsigned long)1073741824 * 8 = 0?

At the moment, the variable "Factor" is 1073741824. When I try to multiply it by 8, I get 0.

I tried this: (unsigned long)1073741824 * (double)8 or (unsigned long)1073741824 * 8.0 , everything works, but the result is a floating point number , but I need an integer.

Tell me why is that? How can I fix it?

unsigned long faktor = 1073741824;
faktor = faktor * (unsigned long)8;


5fc609f6cd0dd991529880.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-12-01
@Arsen00

unsigned long - 2 32 -1 = 4'294'967'295
​​1'073'741'824 * 8 = 8'589'934'592, which is greater than the maximum value for this type.
Use unsigned __int64 or unsigned long long if available on your system.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question