Jump to content

Programming - calculating max value for data type


Recommended Posts

Some useful formula I came across while studying. You can calculate the maximum value for pretty much any data type in most cases.

Though this appears to be pretty basic stuff, I thought i'd share it with you.

 

Formula : 2^(n-1)-1 (signed)

              2^(n-1) (unsigned)

 

N = Amount of bits

^ = Power

 

For example in Java an integer is 4 bytes which is 32 bits. (1 byte = 8 bits).

 

2^(32-1)-1 = 2147483647 as maximum value for an integer (signed) or -2147483648 (unsigned)

QmXjtKY.png

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...