Libraryless. Click here for Pure Java version (39L/1K).
static int roundUpToPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; ret v+1; } static long roundUpToPowerOfTwo(long v) { long i = Long.highestOneBit(v); ret v > i ? i << 1 : i; }
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1011273 |
Snippet name: | roundUpToPowerOfTwo |
Eternal ID of this version: | #1011273/6 |
Text MD5: | 1ed6df56552a26e7f917c5e1a13182e2 |
Transpilation MD5: | 50db441e64c21ec1f7462c5f7c25b453 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-31 16:49:28 |
Source code size: | 253 bytes / 14 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 557 / 690 |
Version history: | 5 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1032252 - iceil_divideByPowerOfTwo #1033645 - roundUpToPowerOfTwo_alternateMethod |