For Data Type:int


#1

For Data Type:int, why does this type only allow values between -2,147,483,648 and 2,147,483,647. What if a website hits more views than 2,147,483,647. Can this setting be changed, and how?


#2

The largest integer that can be stored will be constrained by how many bytes of memory are allocated when they are defined. There are two types of integers: short and long. In some systems, a short integer will be given four bytes (remember that one bit is the sign bit) and a long integer will be given eight bytes.

Four bytes less the sign bit is 31 bits.

2 ** 31  =>  2 147 483 648

Recall that a negative number is the two’s complement of its binary positive.

0000 0000 0000 0000 0000 0000 0000 0001    =>  1
1111 1111 1111 1111 1111 1111 1111 1111    => -1

(Flip all the bits and add 1.)

 '0b01111111111111111111111111111111'  =>  2,147,483,647
'-0b10000000000000000000000000000000'  => -2,147,483,648

add 1…

'-0b10000000000000000000000000000001'  => -2,147,483,647

#3

Thank you so much for the response. If it not too much trouble, could you help me to better understand a Java assignment please? I’ve tried to do it, but I find it very confusing.


#4

Java is a low level language that expects the developer to manage memory. It is not the language to start out with unless you are a true geek/nerd. For us ordinary folk, it is better to start with a high level language that does a lot of the heavy lifting for us as OS concerns go. We can focus on the language given the protected environment it executes in.

JavaScript is the way to go, I would say. At least until the basic progrramming concepts are cemented. Then other interpreted languages present themselves, Python and Ruby on this site. They also exist in a protected environment.

Java, C, C++, C#, etc. (the low-level languages) expect more than a rote level of skill from practitioners. They are languages to pursue when you have programming concepts down pat. Then you will really see what those languages are about.

As for your question, it would be easier to answer if it was in the Learn JavaScript track. It’s a little out of place in this course.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.