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.

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

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: 218 / 322
Version history: 2 change(s)
Referenced in: [show references]