Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

17
LINES

< > BotCompany Repo | #1026146 // nextPowerOfTwo - probable duplicate of roundUpToPowerOfTwo

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (42L) is out of date.

1  
/** Return the least power of two greater than or equal to the specified value.
2  
  *
3  
  * <p>Note that this function will return 1 when the argument is 0.
4  
  *
5  
  * @param x a long integer smaller than or equal to 2<sup>62</sup>.
6  
  * @return the least power of two greater than or equal to the specified value.
7  
  */
8  
static long nextPowerOfTwo( long x ) {
9  
  if ( x == 0 ) return 1;
10  
  x--;
11  
  x |= x >> 1;
12  
  x |= x >> 2;
13  
  x |= x >> 4;
14  
  x |= x >> 8;
15  
  x |= x >> 16;
16  
  return ( x | x >> 32 ) + 1;
17  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1026146
Snippet name: nextPowerOfTwo - probable duplicate of roundUpToPowerOfTwo
Eternal ID of this version: #1026146/3
Text MD5: 4fb27bb074a11cfc65eb6338d7264020
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-08-02 21:02:00
Source code size: 507 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 167 / 251
Version history: 2 change(s)
Referenced in: [show references]