Libraryless. Click here for Pure Java version (39L/1K).
1 | static int roundUpToPowerOfTwo(int v) { |
2 | v--; |
3 | v |= v >> 1; |
4 | v |= v >> 2; |
5 | v |= v >> 4; |
6 | v |= v >> 8; |
7 | v |= v >> 16; |
8 | ret v+1; |
9 | } |
10 | |
11 | static long roundUpToPowerOfTwo(long v) { |
12 | long i = Long.highestOneBit(v); |
13 | ret v > i ? i << 1 : i; |
14 | } |
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: | 558 / 691 |
Version history: | 5 change(s) |
Referenced in: | [show references] |