Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Encode and decode floating point integers

Python 3, 268 250 235 233 210 197 148 bytes def a(n):e=(n>>6).bit_length();f=2**e;l=n&(f-1);N=(n>>e)&31;return((e+(n>31))<<5)+N+(2*l+N%2>f) def b(r):E=r>>5...

posted 3y ago by General Sebast1an‭  ·  edited 3y ago by General Sebast1an‭

Answer
#8: Post edited by user avatar General Sebast1an‭ · 2021-10-04T00:07:47Z (about 3 years ago)
  • # [Python 3], <s>268</s> <s>250</s> <s>235</s> <s>233</s> <s>210</s> 197 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31;M=N+((2*l==f and N%2)or 2*l&gt;f);E=e+(n&gt;31)
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):E=r&gt;&gt;5;return((r&amp;31)+32*(E&gt;0))*2**(E-(E&gt;0))
  • </code></pre>
  • [Try it online!][TIO-kuaxnrge]
  • Golfed 15 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4678#comment-14008). Golfed another 23 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4686#comment-14019). Golfed another 13 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4687#comment-14020).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kuaxnrge]: https://tio.run/##lZTbitswEIavracQgS6SkwVbPiS2V4aFulBoQmEvl6XkIBODKwcfKCXNs2d1cIId4YvmYvDk88xo5h/r9Lc9Vty7Xg8sh1vEcQwsRh1g/TkWJYM8pcS2mR36MZtTF1i58pOS8ieUP7s42VDE05ThJ89N1nQzR4jYJaUiGT/AzReCqxqKf9IcJxllc/Gy52JgFTlcU@qROBNpRaCoWLO2qznKXl4C/G8N5IF2qMZxRus0DZIeo1pUwnOP2ChLHYxtcR6UPWvnmnd83xYVbyCFZ2DNGN9XBzaL4XYhvAPrvR24AFWgZU2LbkG/@PY3i2HT1gtY8FPX9s9V194cOZ6aNV3Z0nup91H8B1KhusX@VdpnONUFF@VmP1/f3rKvMTyPIi/orKum/gXL8@to6c5EOlY27J7h2@v3H/@VYQGbY9WVB7hj8NwfRycGcgb7bcPkzN6BhW5DW0Dxc7TFi0fgamsAz9XWBERbA4SetibwtTVBMAVCjU2w1NgEqykQTYCloxM@ApeoPiLfBP4UCKaA6iMKTKD6iEITrKZANAE8ZwooBSOjQRKEutIDIA6REYQ8Kug7SnMSyD4k6b8/c7GGYLRYAzBerCEYLdYAjBdrCEaLNQTBUPQh0Iu1MkDkqZmYxSNfS2@CQCtsgtF4h2CpZDFqaNGFLAYI5XQD14ggckeJ44Ym8CXwjeJCPC0kBh8A5OIyv10X4oq8Pzexukjtm4@vnw "Python 3 – Try It Online"
  • # [Python 3], <s>268</s> <s>250</s> <s>235</s> <s>233</s> <s>210</s> <s>197</s> 148 bytes
  • <!-- language-all: lang-python -->
  • def a(n):e=(n>>6).bit_length();f=2**e;l=n&(f-1);N=(n>>e)&31;return((e+(n>31))<<5)+N+(2*l+N%2>f)
  • def b(r):E=r>>5;return((r&31)+32*(E>0))*2**(E-(E>0))
  • [Try it online!][TIO-kubw77lt]
  • Golfed 15 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4678#comment-14008). Golfed another 23 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4686#comment-14019). Golfed another 13 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4687#comment-14020). Golfed another 49 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4693#comment-14028).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kubw77lt]: https://tio.run/##lZTfi5tAEMefs3/FEuixq17R9UeiOYWDplAooXCPx3Hkx9oE7Bp0fSghf3vq7mrQDD7Uh8Hx48w48x33/FceS@Hfbgee4y0RNOEpEVkW0a@7k/wsuPgtj4Su8pRZFl8VqXgi@bNHVxv9GqdPvrequGwqQQi322e@R@nLS0jtjU2YVdibLyzLKVL5d6SiyTqtsiy8x1RtAmr7zCLrzKXUasuQ9bNxbnkj9vJUihqn@IJmcy725YHPE7x1Wu/AO2@HrkgXkLyWpA/6FNs/PMG1rBx8EudGdvdlI3uHJmhW8bopZHov9T6K/yA6lKLZKcfdq2mX4VydRFtu/uv17W39LcGXUeSVXEzVLLhS9f0mWrnzNh0van7P8P31x8//yuDg@lg2xQHvOL50n2MSIzWD/bbmambvaEb6oTm4vVxjqfMIPGMB8D1jIWDGAhD5xkIQGAtBOAUigyFYGAzBcgrEE2DhmoSPwGO6jziAIJgC4RTQfcQhBLqPOIJgOQXiCeC7U0ArGIMGWRiZSg@AuUxFMPaoYOBqzVmo@lCk@//gYg3BaLEGYLxYQzBarAEYL9YQjBZrCMKh6ENgFmsJQOzrmcDicWCkhyA0CkMwGu8QLLQsoIYRvZUFgEhNN/RABFM7ylwvgiBQIADFW/GMkBR9IJSXFe6Pi/aIvN/XiT5Ird6nt38 "Python 3 – Try It Online"
#7: Post edited by user avatar General Sebast1an‭ · 2021-10-03T08:01:19Z (about 3 years ago)
  • # [Python 3], <s>268</s> <s>250</s> <s>235</s> <s>233</s> 210 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;if n&lt;32:return n
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31;M=N+((2*l==f and N%2)or 2*l&gt;f);E=e+1
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):E=r&gt;&gt;5;return((r&amp;31)+32*(E&gt;0))*2**(E-(E&gt;0))
  • </code></pre>
  • [Try it online!][TIO-kuavzysk]
  • Don't mind me always golfing your original implementations. :)
  • Golfed 15 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4678#comment-14008). Golfed another 23 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4686#comment-14019).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kuavzysk]: https://tio.run/##lZRbi@IwFMefm08RhBmS6kCbXrTVFAa2CwurLMzjMAxqUxS6qfTCsrh@dieXKq2hD9uHQ4@/nvPPuZjT3@ZQcu96zVgOt4jjGFjHHPKVR@KKNW3FIQcWow6w/hyOBYM8ocS2mR36MZtSF1i58pcF5c8of3HxckMRTxKGnz13uaabKULELigV6XkGN08ElxUUvyQ5XqaUTV0luKZUKKYio4gRYlobpatVgP@tgTzdDlU4TmmVJMGyw6gSInjqERuliYOxLY6C0hftXPOW75tjyWtI4RlYE8b3ZcYmMdzOhJexztuBC1ACDasbdAv65NvfLIZ1U83gkZ/apnsv2@bmyF5VrG6Lht6l3gfxH0iFYlVi9yntMpyqIxdyk1@vb2/ptxieB5EXdNaqiX/B8vw6WroTkY4VNbtn@P764@d/ZZjB@lC2RQZ3DJ674@jEQPZgv62Z7Nk7sNCtaTMoHkdbPHsErrYG8FxtTUC0NUDoaWsCX1sTBGMg1NgEc41NsBgD0QiYOzrhI3CJqiPyTeCPgWAMqDqiwASqjig0wWIMRCPAc8aAmmBkFEiCUCs9AOIQGUHI4wR9R82cBLIOSbr/n7lYfTBYrB4YLlYfDBarB4aL1QeDxeqDoD/0PtCLtTBA5KmemOKRr0dvgkBP2ASD9vbBXI3F0NBDF2MxQCi7G7hGBJE7Shw3NIEvgW@Ii@HpQWLwAUAu7vHbdSGuyPt7HauL1L75@PoF "Python 3 – Try It Online"
  • # [Python 3], <s>268</s> <s>250</s> <s>235</s> <s>233</s> <s>210</s> 197 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31;M=N+((2*l==f and N%2)or 2*l&gt;f);E=e+(n&gt;31)
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):E=r&gt;&gt;5;return((r&amp;31)+32*(E&gt;0))*2**(E-(E&gt;0))
  • </code></pre>
  • [Try it online!][TIO-kuaxnrge]
  • Golfed 15 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4678#comment-14008). Golfed another 23 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4686#comment-14019). Golfed another 13 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4687#comment-14020).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kuaxnrge]: https://tio.run/##lZTbitswEIavracQgS6SkwVbPiS2V4aFulBoQmEvl6XkIBODKwcfKCXNs2d1cIId4YvmYvDk88xo5h/r9Lc9Vty7Xg8sh1vEcQwsRh1g/TkWJYM8pcS2mR36MZtTF1i58pOS8ieUP7s42VDE05ThJ89N1nQzR4jYJaUiGT/AzReCqxqKf9IcJxllc/Gy52JgFTlcU@qROBNpRaCoWLO2qznKXl4C/G8N5IF2qMZxRus0DZIeo1pUwnOP2ChLHYxtcR6UPWvnmnd83xYVbyCFZ2DNGN9XBzaL4XYhvAPrvR24AFWgZU2LbkG/@PY3i2HT1gtY8FPX9s9V194cOZ6aNV3Z0nup91H8B1KhusX@VdpnONUFF@VmP1/f3rKvMTyPIi/orKum/gXL8@to6c5EOlY27J7h2@v3H/@VYQGbY9WVB7hj8NwfRycGcgb7bcPkzN6BhW5DW0Dxc7TFi0fgamsAz9XWBERbA4SetibwtTVBMAVCjU2w1NgEqykQTYCloxM@ApeoPiLfBP4UCKaA6iMKTKD6iEITrKZANAE8ZwooBSOjQRKEutIDIA6REYQ8Kug7SnMSyD4k6b8/c7GGYLRYAzBerCEYLdYAjBdrCEaLNQTBUPQh0Iu1MkDkqZmYxSNfS2@CQCtsgtF4h2CpZDFqaNGFLAYI5XQD14ggckeJ44Ym8CXwjeJCPC0kBh8A5OIyv10X4oq8Pzexukjtm4@vnw "Python 3 – Try It Online"
#6: Post edited by user avatar General Sebast1an‭ · 2021-10-03T07:14:40Z (about 3 years ago)
  • # [Python 3], <s>268</s> <s>250</s> <s>235</s> 233 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;if n&lt;32:return n
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31;M=N+((2*l==f and N%2)or 2*l&gt;f);E=e+1
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):
  • &#9;E=r&gt;&gt;5;M=r&amp;31
  • &#9;if E==0:e=0;m=M
  • &#9;else:e=E-1;m=M+32
  • &#9;return m*2**e
  • </code></pre>
  • [Try it online!][TIO-kuajx5jm]
  • Don't mind me always golfing your original implementations. :)
  • Golfed 15 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4678#comment-14008).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kuajx5jm]: https://tio.run/##lZTbitswEIavracQgS6SkwVbPiR2IsNCXSg0obCXy7LkIJOAIwcfKCXNs6c62Isd4YvNxeDJ55l/RjPW5W99LLh3vx9YBreI4xhYpwzylUfiktVNySEHFqMOsP4cTzmDPKHEtpkd@jGbUhdYmfKXOeVPKHt28XJDEU8Shp88d7mmmylCxM4pFen5AW6@EVyUUPyTZHiZUjZ1leCaUqGYiowiRohpbZSuVgH@twayuh0qZXUpLZMkEG@VQkDFppQ6sShxeaZrUWteMeGlz670px7pksGzLSu9Zw3f16eCV5DCK7AmjO@LA5vEcDsT3oG13g7cgNKtWVWjLuiDb88shlVdzuCJX5q6fS6aunNkkSWrmrymn1Jvg/h3pEKxqr59lbYZLuWJC7nJ75fX1/R7DK@DyBu6atXEv2FZv46W7gS3vXcZfrz8/PWlDDNYHYsmP8Adg9e2HJ0YyDPYbysmz@wNWKg7tBkUP0dbPHsErrYG8FxtTUC0NUDoaWsCX1sTBGMg1NgEc41NsBgD0QiYOzrhI3CJ6iPyTeCPgWAMqD6iwASqjyg0wWIMRCPAc8aAmmBkNEiCUCs9AOIQGUHI4wR9R82cBLIPSdrvz1ysPhgsVg8MF6sPBovVA8PF6oPBYvVB0B96H@jFWhgg8tSZmOKRr0dvgkBP2ASD4@2DuRqLoaGHLsZigFCebuAaEUTuKHHc0AS@BL4hLoanB4nBOwCZuN6760JckZ/PVawuUrvz8f0/ "Python 3 – Try It Online"
  • # [Python 3], <s>268</s> <s>250</s> <s>235</s> <s>233</s> 210 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;if n&lt;32:return n
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31;M=N+((2*l==f and N%2)or 2*l&gt;f);E=e+1
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):E=r&gt;&gt;5;return((r&amp;31)+32*(E&gt;0))*2**(E-(E&gt;0))
  • </code></pre>
  • [Try it online!][TIO-kuavzysk]
  • Don't mind me always golfing your original implementations. :)
  • Golfed 15 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4678#comment-14008). Golfed another 23 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4686#comment-14019).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kuavzysk]: https://tio.run/##lZRbi@IwFMefm08RhBmS6kCbXrTVFAa2CwurLMzjMAxqUxS6qfTCsrh@dieXKq2hD9uHQ4@/nvPPuZjT3@ZQcu96zVgOt4jjGFjHHPKVR@KKNW3FIQcWow6w/hyOBYM8ocS2mR36MZtSF1i58pcF5c8of3HxckMRTxKGnz13uaabKULELigV6XkGN08ElxUUvyQ5XqaUTV0luKZUKKYio4gRYlobpatVgP@tgTzdDlU4TmmVJMGyw6gSInjqERuliYOxLY6C0hftXPOW75tjyWtI4RlYE8b3ZcYmMdzOhJexztuBC1ACDasbdAv65NvfLIZ1U83gkZ/apnsv2@bmyF5VrG6Lht6l3gfxH0iFYlVi9yntMpyqIxdyk1@vb2/ptxieB5EXdNaqiX/B8vw6WroTkY4VNbtn@P764@d/ZZjB@lC2RQZ3DJ674@jEQPZgv62Z7Nk7sNCtaTMoHkdbPHsErrYG8FxtTUC0NUDoaWsCX1sTBGMg1NgEc41NsBgD0QiYOzrhI3CJqiPyTeCPgWAMqDqiwASqjig0wWIMRCPAc8aAmmBkFEiCUCs9AOIQGUHI4wR9R82cBLIOSbr/n7lYfTBYrB4YLlYfDBarB4aL1QeDxeqDoD/0PtCLtTBA5KmemOKRr0dvgkBP2ASD9vbBXI3F0NBDF2MxQCi7G7hGBJE7Shw3NIEvgW@Ii@HpQWLwAUAu7vHbdSGuyPt7HauL1L75@PoF "Python 3 – Try It Online"
#5: Post edited by user avatar General Sebast1an‭ · 2021-10-03T02:58:54Z (about 3 years ago)
  • # [Python 3], <s>268</s> <s>250</s> <s>235</s> 233 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;if n&lt;32:return n
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31;M=N+((2*l==f and N%2)or 2*l&gt;f);E=e+1
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):
  • &#9;E=r&gt;&gt;5;M=r&amp;31
  • &#9;if E==0:e=0;m=M
  • &#9;else:e=E-1;m=M+32
  • &#9;return m*2**e
  • </code></pre>
  • [Try it online!][TIO-kuajx5jm]
  • Don't mind me always golfing your original implementations. :)
  • Golfed 15 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4678#comment-14008).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kuajx5jm]: https://tio.run/##lZTbitswEIavracQgS6SkwVbPiR2IsNCXSg0obCXy7LkIJOAIwcfKCXNs6c62Isd4YvNxeDJ55l/RjPW5W99LLh3vx9YBreI4xhYpwzylUfiktVNySEHFqMOsP4cTzmDPKHEtpkd@jGbUhdYmfKXOeVPKHt28XJDEU8Shp88d7mmmylCxM4pFen5AW6@EVyUUPyTZHiZUjZ1leCaUqGYiowiRohpbZSuVgH@twayuh0qZXUpLZMkEG@VQkDFppQ6sShxeaZrUWteMeGlz670px7pksGzLSu9Zw3f16eCV5DCK7AmjO@LA5vEcDsT3oG13g7cAFDCNatq1EV98O2ZxbCqyxk88UtTt89FU3eOrLJkVZPX9FPrbRD/jlQoVuW3r9I2w6U8cSE3@f3y@pp@j@F1EHlDV62a@DcsG9DR0p3gtvkuw4@Xn7@@lGEGq2PR5Ae4Y/DalqMTA3kG@23F5KG9AQt1pzaD4udoi2ePwNXWAJ6rrQmItgYIPW1N4GtrgmAMhBqbYK6xCRZjIBoBc0cnfAQuUX1Evgn8MRCMAdVHFJhA9RGFJliMgWgEeM4YUBOMjAZJEGqlB0AcIiMIeZyg76iZk0D2IUn7AZqL1QeDxeqB4WL1wWCxemC4WH0wWKw@CPpD7wO9WAsDRJ46E1M88vXoTRDoCZtgcLx9MFdjMTT00MVYDBDK0w1cI4LIHSWOG5rAl8A3xMXw9CAxeAcgE/d7d12IK/LzuYrVRWp3Pr7/Bw "Python 3 – Try It Online"
  • # [Python 3], <s>268</s> <s>250</s> <s>235</s> 233 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;if n&lt;32:return n
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31;M=N+((2*l==f and N%2)or 2*l&gt;f);E=e+1
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):
  • &#9;E=r&gt;&gt;5;M=r&amp;31
  • &#9;if E==0:e=0;m=M
  • &#9;else:e=E-1;m=M+32
  • &#9;return m*2**e
  • </code></pre>
  • [Try it online!][TIO-kuajx5jm]
  • Don't mind me always golfing your original implementations. :)
  • Golfed 15 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4678#comment-14008).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kuajx5jm]: https://tio.run/##lZTbitswEIavracQgS6SkwVbPiR2IsNCXSg0obCXy7LkIJOAIwcfKCXNs6c62Isd4YvNxeDJ55l/RjPW5W99LLh3vx9YBreI4xhYpwzylUfiktVNySEHFqMOsP4cTzmDPKHEtpkd@jGbUhdYmfKXOeVPKHt28XJDEU8Shp88d7mmmylCxM4pFen5AW6@EVyUUPyTZHiZUjZ1leCaUqGYiowiRohpbZSuVgH@twayuh0qZXUpLZMkEG@VQkDFppQ6sShxeaZrUWteMeGlz670px7pksGzLSu9Zw3f16eCV5DCK7AmjO@LA5vEcDsT3oG13g7cgNKtWVWjLuiDb88shlVdzuCJX5q6fS6aunNkkSWrmrymn1Jvg/h3pEKxqr59lbYZLuWJC7nJ75fX1/R7DK@DyBu6atXEv2FZv46W7gS3vXcZfrz8/PWlDDNYHYsmP8Adg9e2HJ0YyDPYbysmz@wNWKg7tBkUP0dbPHsErrYG8FxtTUC0NUDoaWsCX1sTBGMg1NgEc41NsBgD0QiYOzrhI3CJ6iPyTeCPgWAMqD6iwASqjyg0wWIMRCPAc8aAmmBkNEiCUCs9AOIQGUHI4wR9R82cBLIPSdrvz1ysPhgsVg8MF6sPBovVA8PF6oPBYvVB0B96H@jFWhgg8tSZmOKRr0dvgkBP2ASD4@2DuRqLoaGHLsZigFCebuAaEUTuKHHc0AS@BL4hLoanB4nBOwCZuN6760JckZ/PVawuUrvz8f0/ "Python 3 – Try It Online"
#4: Post edited by user avatar General Sebast1an‭ · 2021-10-03T01:35:23Z (about 3 years ago)
  • # [Python 3], <s>268</s> <s>250</s> 235 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;if n&lt;32:return n
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31
  • &#9;M=N+((2*l==f and N%2)or 2*l&gt;f)
  • &#9;E=e+1
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):
  • &#9;E=r&gt;&gt;5;M=r&amp;31
  • &#9;if E==0:e=0;m=M
  • &#9;else:e=E-1;m=M+32
  • &#9;return m*2**e
  • </code></pre>
  • [Try it online!][TIO-kuahuczz]
  • Don't mind me always golfing your original implementations. :)
  • Golfed 15 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4678#comment-14008).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kuahuczz]: https://tio.run/##lZTbitswEIavracQgS6SkwVbPiR2IsNCXSg0obCXy7LkIJOAIwcfKCXNs6c62Isd4YvNxeDJ55l/RjPW5W99LLh3vx9YBreI4xhYpwzylUfiktVNySEHFqMOsP4cTzmDPKHEtpkd@jGbUhdYmfKXOeVPKHt28XJDEU8Shp88Qdd0M0WI2DmlIj8/wM03gosSin@SDAMrpWzqKsk1pUIzFTmXaymn1VG6WgX43xrI@naolPWltEySQLxVKgkRm1LqxKLI5ZmuRbV5xYSXPrvSn3qkSwbPtqz1njV8X58KXkEKr8CaML4vDmwSw@1MeAfWejtwA0AJ16yqURf1wbdnFsOqLmfwxC9N3T4XTd05ssqSVU1e00@tt0H8O1KhWJXfvkrbDJfyxIXc5PfL62v6PYbXQeQNXbVq4t@wbEBHS3eC2@a7DD9efv76UoYZrI5Fkx/gjsFrW45ODOQZ7LcVk4f2BizUndoMip@jLZ49AldbA3iutiYg2hog9LQ1ga@tCYIxEGpsgrnGJliMgWgEzB2d8BG4RPUR@Sbwx0AwBlQfUWAC1UcUmmAxBqIR4DljQE0wMhokQaiVHgBxiIwg5HGCvqNmTgLZhyTtB2guVh8MFqsHhovVB4PF6oHhYvXBYLH6IOgPvQ/0Yi0MEHnqTEzxyNejN0GgJ2yCwfH2wVyNxdDQQxdjMUAoTzdwjQgid5Q4bmgCXwLfEBfD04PE4B2ATFzw3XUhrsjP5ypWF6nd@fj@Hw "Python 3 – Try It Online"
  • # [Python 3], <s>268</s> <s>250</s> <s>235</s> 233 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;if n&lt;32:return n
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31;M=N+((2*l==f and N%2)or 2*l&gt;f);E=e+1
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):
  • &#9;E=r&gt;&gt;5;M=r&amp;31
  • &#9;if E==0:e=0;m=M
  • &#9;else:e=E-1;m=M+32
  • &#9;return m*2**e
  • </code></pre>
  • [Try it online!][TIO-kuajx5jm]
  • Don't mind me always golfing your original implementations. :)
  • Golfed 15 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4678#comment-14008).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kuajx5jm]: https://tio.run/##lZTbitswEIavracQgS6SkwVbPiR2IsNCXSg0obCXy7LkIJOAIwcfKCXNs6c62Isd4YvNxeDJ55l/RjPW5W99LLh3vx9YBreI4xhYpwzylUfiktVNySEHFqMOsP4cTzmDPKHEtpkd@jGbUhdYmfKXOeVPKHt28XJDEU8Shp88d7mmmylCxM4pFen5AW6@EVyUUPyTZHiZUjZ1leCaUqGYiowiRohpbZSuVgH@twayuh0qZXUpLZMkEG@VQkDFppQ6sShxeaZrUWteMeGlz670px7pksGzLSu9Zw3f16eCV5DCK7AmjO@LA5vEcDsT3oG13g7cAFDCNatq1EV98O2ZxbCqyxk88UtTt89FU3eOrLJkVZPX9FPrbRD/jlQoVuW3r9I2w6U8cSE3@f3y@pp@j@F1EHlDV62a@DcsG9DR0p3gtvkuw4@Xn7@@lGEGq2PR5Ae4Y/DalqMTA3kG@23F5KG9AQt1pzaD4udoi2ePwNXWAJ6rrQmItgYIPW1N4GtrgmAMhBqbYK6xCRZjIBoBc0cnfAQuUX1Evgn8MRCMAdVHFJhA9RGFJliMgWgEeM4YUBOMjAZJEGqlB0AcIiMIeZyg76iZk0D2IUn7AZqL1QeDxeqB4WL1wWCxemC4WH0wWKw@CPpD7wO9WAsDRJ46E1M88vXoTRDoCZtgcLx9MFdjMTT00MVYDBDK0w1cI4LIHSWOG5rAl8A3xMXw9CAxeAcgE/d7d12IK/LzuYrVRWp3Pr7/Bw "Python 3 – Try It Online"
#3: Post edited by user avatar General Sebast1an‭ · 2021-10-03T00:38:00Z (about 3 years ago)
  • # [Python 3], <s>268</s> 250 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;if n&lt;32:return n
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31
  • &#9;if(2*l==f and N%2==1)or 2*l&gt;f:M=N+1
  • &#9;else:M=N
  • &#9;E=e+1
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):
  • &#9;E=r&gt;&gt;5;M=r&amp;31
  • &#9;if E==0:e=0;m=M
  • &#9;else:e=E-1;m=M+32
  • &#9;return m*2**e
  • </code></pre>
  • [Try it online!][TIO-ku9znx9h]
  • Don't mind me always golfing your original implementations. :)
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku9znx9h]: https://tio.run/##lZRbi6MwFICfza8IhR2MdUDjpdU2wsC6sLAtC/M4DEMvkQo2Fi8sS7e/vZuLDtrgw/ThkNMv537M5W9zKpl3vx9pBncmQzEw8gyytYfjijZtxSADBiUOMP6c8oJClhBsWdQK/ZjOiQuMTOqrgrAnM3t20WpLTJYkFD15rvBlYqsghDtnR7j9hglxUVlB/meSxRuynfNLtKipOAMjJXQureCGEJ5CykOsNiK6SsZM1@sA/dsAke7erES6KamSJOC3qi4iTAlxYp7z6kw2nXdK0mdX6HMP987g2RKp37OWHZq8ZDUk8AqMGWWH8khnMdzZXDvSTtuDGwAycEPrxuytPtjuTGNYN5UNc3Zpm@5ctk2viCwrWrdFQz5jvY3s301pimT63VXSebhUOePhZr9fXl/T7zG8jixv5lVFTfwbEgUoa6HOUFd87@HHy89fX/Jgw/pUtsUR7im8dukox0D04LCrqWjaGzDMvms25D9HSWQ/AldJDXiukjrASmog9JTUga@kDoIpECqsg4XCOlhOgWgCLBzl8BG4WNYR@Trwp0AwBWQdUaADWUcU6mA5BaIJ4DlTQE4w0grEQagiPQDsYGGB8eMEfUfOHAeiDkG6D1BfrCEYLdYAjBdrCEaLNQDjxRqC0WINQTAc@hCoxVpqIPJkT/Tgka9Gr4NATVgHo/YOwUKORYuhhs7HooFQdDdwNQssdhQ7bqgDXwBfC86HpwaJwDsAGX/v@@eCP5Gf5zqWD6nV6@j@Hw "Python 3 – Try It Online"
  • # [Python 3], <s>268</s> <s>250</s> 235 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;if n&lt;32:return n
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31
  • &#9;M=N+((2*l==f and N%2)or 2*l&gt;f)
  • &#9;E=e+1
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):
  • &#9;E=r&gt;&gt;5;M=r&amp;31
  • &#9;if E==0:e=0;m=M
  • &#9;else:e=E-1;m=M+32
  • &#9;return m*2**e
  • </code></pre>
  • [Try it online!][TIO-kuahuczz]
  • Don't mind me always golfing your original implementations. :)
  • Golfed 15 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4678#comment-14008).
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kuahuczz]: https://tio.run/##lZTbitswEIavracQgS6SkwVbPiR2IsNCXSg0obCXy7LkIJOAIwcfKCXNs6c62Isd4YvNxeDJ55l/RjPW5W99LLh3vx9YBreI4xhYpwzylUfiktVNySEHFqMOsP4cTzmDPKHEtpkd@jGbUhdYmfKXOeVPKHt28XJDEU8Shp88Qdd0M0WI2DmlIj8/wM03gosSin@SDAMrpWzqKsk1pUIzFTmXaymn1VG6WgX43xrI@naolPWltEySQLxVKgkRm1LqxKLI5ZmuRbV5xYSXPrvSn3qkSwbPtqz1njV8X58KXkEKr8CaML4vDmwSw@1MeAfWejtwA0AJ16yqURf1wbdnFsOqLmfwxC9N3T4XTd05ssqSVU1e00@tt0H8O1KhWJXfvkrbDJfyxIXc5PfL62v6PYbXQeQNXbVq4t@wbEBHS3eC2@a7DD9efv76UoYZrI5Fkx/gjsFrW45ODOQZ7LcVk4f2BizUndoMip@jLZ49AldbA3iutiYg2hog9LQ1ga@tCYIxEGpsgrnGJliMgWgEzB2d8BG4RPUR@Sbwx0AwBlQfUWAC1UcUmmAxBqIR4DljQE0wMhokQaiVHgBxiIwg5HGCvqNmTgLZhyTtB2guVh8MFqsHhovVB4PF6oHhYvXBYLH6IOgPvQ/0Yi0MEHnqTEzxyNejN0GgJ2yCwfH2wVyNxdDQQxdjMUAoTzdwjQgid5Q4bmgCXwLfEBfD04PE4B2ATFzw3XUhrsjP5ypWF6nd@fj@Hw "Python 3 – Try It Online"
#2: Post edited by user avatar General Sebast1an‭ · 2021-10-02T16:08:14Z (about 3 years ago)
  • # [Python 3], 268 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n:int)-&gt;int:
  • &#9;if n&lt;32:return n
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31
  • &#9;if(2*l==f and N%2==1)or 2*l&gt;f:M=N+1
  • &#9;else:M=N
  • &#9;E=e+1
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r:int)-&gt;int:
  • &#9;E=r&gt;&gt;5;M=r&amp;31
  • &#9;if E==0:e=0;m=M
  • &#9;else:e=E-1;m=M+32
  • &#9;return m*2**e
  • </code></pre>
  • [Try it online!][TIO-ku9wp6bz]
  • Don't mind me always golfing your original implementations. :)
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku9wp6bz]: https://tio.run/##lZRJi9swFIDP1q8QgQ6Wk4AtL4mVyDBQFwpNKMxxGEoWmQQcOXihlDS/PdViD3aED83hoZdPb3/W9U99Krj/eBxZBnc2J2deo3kiJAHWOYN87WNSsropOeTAYtQF1u/TOWeQJxQ7DnOigLAp9YCVKX2VU/5iZ3MPrbbU5knC0IvvSV82dnJKRRR@hNsvmFIPFSUUfyYZ2dDtVFxiecXkGVgpZVNlBTeUihRSEWK1kdF1Mna6Xofo7wbIvPd2Ocg7pWWShOJ62YaGKaUuEcmvLnTThmE0nXtSn/q48wovjqzhkTX8UJ8LXkEKb8CaMH4ojmxC4G4mtCNrtT24A6AyqFlV253VL767MAKrupzBM782dXsumrpTEJEhqyav6Wes94H9h61MkUq/vUpbD9dS1Glnk5@vb2/pVwJvA8u7fdNRk@COZAHaWqoT1Bbfefj2@v3Hf3mYwepUNPkR7hm8telox0D24LCrmGzaO7DsrmszKH6ulmj2DDwtDeB7WpoAa2mAyNfSBIGWJgjHQKSxCRYam2A5BuIRsHC1w2fgYVVHHJggGAPhGFB1xKEJVB1xZILlGIhHgO@OATXB2CgQh5GO9ASwi6UFxs8TDFw1cxzKOiRpP0BzsfpgsFg9MFysPhgsVg8MF6sPBovVB2F/6H2gF2tpgNhXPTGDx4EevQlCPWETDNrbBws1FiOGHroYiwEi2d3QMyyw3FHsepEJAgkCI7gYnh4kAh8AZOLh754L8UR@niuiHlKn09HjHw "Python 3 – Try It Online"
  • # [Python 3], <s>268</s> 250 bytes
  • <!-- language-all: lang-python -->
  • <pre><code>def a(n):
  • &#9;if n&lt;32:return n
  • &#9;e=0
  • &#9;while n&gt;=2**e*64:e+=1
  • &#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31
  • &#9;if(2*l==f and N%2==1)or 2*l&gt;f:M=N+1
  • &#9;else:M=N
  • &#9;E=e+1
  • &#9;if M==32:E+=1;M=0
  • &#9;return(E&lt;&lt;5)|M
  • def b(r):
  • &#9;E=r&gt;&gt;5;M=r&amp;31
  • &#9;if E==0:e=0;m=M
  • &#9;else:e=E-1;m=M+32
  • &#9;return m*2**e
  • </code></pre>
  • [Try it online!][TIO-ku9znx9h]
  • Don't mind me always golfing your original implementations. :)
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ku9znx9h]: https://tio.run/##lZRbi6MwFICfza8IhR2MdUDjpdU2wsC6sLAtC/M4DEMvkQo2Fi8sS7e/vZuLDtrgw/ThkNMv537M5W9zKpl3vx9pBncmQzEw8gyytYfjijZtxSADBiUOMP6c8oJClhBsWdQK/ZjOiQuMTOqrgrAnM3t20WpLTJYkFD15rvBlYqsghDtnR7j9hglxUVlB/meSxRuynfNLtKipOAMjJXQureCGEJ5CykOsNiK6SsZM1@sA/dsAke7erES6KamSJOC3qi4iTAlxYp7z6kw2nXdK0mdX6HMP987g2RKp37OWHZq8ZDUk8AqMGWWH8khnMdzZXDvSTtuDGwAycEPrxuytPtjuTGNYN5UNc3Zpm@5ctk2viCwrWrdFQz5jvY3s301pimT63VXSebhUOePhZr9fXl/T7zG8jixv5lVFTfwbEgUoa6HOUFd87@HHy89fX/Jgw/pUtsUR7im8dukox0D04LCrqWjaGzDMvms25D9HSWQ/AldJDXiukjrASmog9JTUga@kDoIpECqsg4XCOlhOgWgCLBzl8BG4WNYR@Trwp0AwBWQdUaADWUcU6mA5BaIJ4DlTQE4w0grEQagiPQDsYGGB8eMEfUfOHAeiDkG6D1BfrCEYLdYAjBdrCEaLNQDjxRqC0WINQTAc@hCoxVpqIPJkT/Tgka9Gr4NATVgHo/YOwUKORYuhhs7HooFQdDdwNQssdhQ7bqgDXwBfC86HpwaJwDsAGX/v@@eCP5Gf5zqWD6nV6@j@Hw "Python 3 – Try It Online"
#1: Initial revision by user avatar General Sebast1an‭ · 2021-10-02T14:46:00Z (about 3 years ago)
# [Python 3], 268 bytes

<!-- language-all: lang-python -->

<pre><code>def a(n:int)-&gt;int:
&#9;if n&lt;32:return n
&#9;e=0
&#9;while n&gt;=2**e*64:e+=1
&#9;f=2**e;l=n&amp;(f-1);N=(n&gt;&gt;e)&amp;31
&#9;if(2*l==f and N%2==1)or 2*l&gt;f:M=N+1
&#9;else:M=N
&#9;E=e+1
&#9;if M==32:E+=1;M=0
&#9;return(E&lt;&lt;5)|M
def b(r:int)-&gt;int:
&#9;E=r&gt;&gt;5;M=r&amp;31
&#9;if E==0:e=0;m=M
&#9;else:e=E-1;m=M+32
&#9;return m*2**e
</code></pre>

[Try it online!][TIO-ku9wp6bz]

Don't mind me always golfing your original implementations. :)

[Python 3]: https://docs.python.org/3/
[TIO-ku9wp6bz]: https://tio.run/##lZRJi9swFIDP1q8QgQ6Wk4AtL4mVyDBQFwpNKMxxGEoWmQQcOXihlDS/PdViD3aED83hoZdPb3/W9U99Krj/eBxZBnc2J2deo3kiJAHWOYN87WNSsropOeTAYtQF1u/TOWeQJxQ7DnOigLAp9YCVKX2VU/5iZ3MPrbbU5knC0IvvSV82dnJKRRR@hNsvmFIPFSUUfyYZ2dDtVFxiecXkGVgpZVNlBTeUihRSEWK1kdF1Mna6Xofo7wbIvPd2Ocg7pWWShOJ62YaGKaUuEcmvLnTThmE0nXtSn/q48wovjqzhkTX8UJ8LXkEKb8CaMH4ojmxC4G4mtCNrtT24A6AyqFlV253VL767MAKrupzBM782dXsumrpTEJEhqyav6Wes94H9h61MkUq/vUpbD9dS1Glnk5@vb2/pVwJvA8u7fdNRk@COZAHaWqoT1Bbfefj2@v3Hf3mYwepUNPkR7hm8telox0D24LCrmGzaO7DsrmszKH6ulmj2DDwtDeB7WpoAa2mAyNfSBIGWJgjHQKSxCRYam2A5BuIRsHC1w2fgYVVHHJggGAPhGFB1xKEJVB1xZILlGIhHgO@OATXB2CgQh5GO9ASwi6UFxs8TDFw1cxzKOiRpP0BzsfpgsFg9MFysPhgsVg8MF6sPBovVB2F/6H2gF2tpgNhXPTGDx4EevQlCPWETDNrbBws1FiOGHroYiwEi2d3QMyyw3FHsepEJAgkCI7gYnh4kAh8AZOLh754L8UR@niuiHlKn09HjHw "Python 3 – Try It Online"