# How to get the bit size (bit length) of an integer? [closed]

Suppose I have the integer 255, so 11111111 is its base 2 (bit) representation and the bit size of 255 is 8.

How can I calculate the bit size of a (big) integer in Mathematica?

Is there a built in command to do that?

For example, get the bit size of this number:

2927830792549090642223927128245994370407730707421263941027999016984863\ 0912510984361076745426566160527575471588512101075236999502833556564464\ 0143433068092260733442122287098839310773059055086206120153515198219258\ 3398767872924593087999752701698335718220740690349861031458470734962692\ 3038457908116713132220756431585261807276890622491179809166640240727423\ 4638027206000615626040059518008119647495121187340010342599638426421633\ 8576751240728022900245840147015717947277804819529535526416662889228374\ 6706468629147699490658964244983147481584083398771392660755122805961564\ 6232235189593608657475480776903398421238729200205836458726287800099705\ 0358443968871300659117135416050092702254367736854056906749254852543144\ 3694151267594169161940659804689537402197491168015348254792206440317735\ 9044042848797425848100671512433900298757949690015974346822013731231910\ 2955628829900538139966080075143814948778191364059028356066552952768294\ 2164682347620954539325716876951175523562310072129163601000525231574137\ 1600673653354351636549060209732731465253358622650325814782996304822146\ 3881825359514299355098051031632982976355385119756255805491633418151251\ 7936289335488021612731448264926863136612284118410866200550379357890757\ 849558223140502795152578737799914590886592

You can use BitLength or IntegerLength:

BitLength[number]


4091

IntegerLength[number, 2]


4091

• Or Log[2, number] // Ceiling. – Rohit Namjoshi Sep 5 '19 at 3:48
• Also, Log2[number] // Ceiling – Bob Hanlon Sep 5 '19 at 5:27