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 Convert to Hexadecimal

JavaScript (Node.js), 60 bytes n=>{for(l='';n;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l} Try it online! Explanation n=>{for(l='';n;l="0123456789ABCDEF"[n%16]+l,n>>=4);ret...

posted 4d ago by hydroxyl-radical‭  ·  edited 4d ago by hydroxyl-radical‭

Answer
#5: Post edited by user avatar hydroxyl-radical‭ · 2025-05-27T11:13:27Z (4 days ago)
on the left* (please ignore my previous edit doing nothing ??????????????)
  • # [JavaScript (Node.js)], 60 bytes
  • ```javascript
  • n=>{for(l='';n;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}
  • ```
  • [Try it online]!
  • ## Explanation
  • ```javascript
  • n=>{for(l='';n;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}/*
  • l=''; | ⁡Starting with an empty string...
  • for( n; ); | ⁢...loop while n still has hex digits (i.e. nonzero):
  • l="0123456789ABCDEF"[n%16]+l, | ⁣ add the hex digit corresponding to n mod 16
  • n>>=4 | ⁤ then floor division by 16
  • n=>{ return l} | ⁢⁡(in an anonymous arrow function)
  • 💎*/
  • ```
  • Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
  • ## Caveats
  • "It should work at least for all inputs greater than 0 up to the language's default type limit." - the question. (i.e. returning an empty string for 0 is fine) \
  • <sub>"The empty string is a syntactically valid representation of zero in positional notation (in any base), which does not contain leading zeros." - Wikipedia, which agrees with my opinion, but that doesn't matter anyways as stated above</sub>
  • [JavaScript (Node.js)]: https://nodejs.org
  • [Try it online]: https://tio.run/##RdBPb4IwGAbwu5@CmG1to2v4J9aQkojCYYft4NGZ4Gp1NbUYwGWL4bOzAmXriV95@ubNc95/7UtWiGv1rPIDb1iuyspKaaNodD/mBZQUgFCFko5tx/X8WTAni2W8WifpeKsenWA3kVMVRdRHYcGrW6EsWTfTDc1GttUeGlndx9PIGewY28ZL45lxahwMedvk572D2OS93otFZ3f4v0pN3rY7ewnp7RGntUvIWtsnxO0cJ/FMO8NVIS4Q4fIqRQXBuwII6wqSPfuEUArFUZu@j9q1@p7U7fLBC4taky3GuI0Mj2kE0Nbe7fBRyIoXkOmL/wIBForJ24GXkCGEz7lQEAAU/o3OJccyP8GMf185q6yHezu81tX0JfODvnrZvL3iUi@tTuL4A1PYr4NQnelRNQqbXw "JavaScript (Node.js) – Try It Online"
  • # [JavaScript (Node.js)], 60 bytes
  • ```javascript
  • n=>{for(l='';n;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}
  • ```
  • [Try it online]!
  • ## Explanation
  • ```javascript
  • n=>{for(l='';n;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}/*
  • l=''; | ⁡Starting with an empty string...
  • for( n; ); | ⁢...loop while n still has hex digits (i.e. nonzero):
  • l="0123456789ABCDEF"[n%16]+l, | ⁣ add the hex digit corresponding to n mod 16 on the left (so no +=)
  • n>>=4 | ⁤ then floor division by 16
  • n=>{ return l} | ⁢⁡(in an anonymous arrow function)
  • 💎*/
  • ```
  • Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
  • ## Caveats
  • "It should work at least for all inputs greater than 0 up to the language's default type limit." - the question. (i.e. returning an empty string for 0 is fine) \
  • <sub>"The empty string is a syntactically valid representation of zero in positional notation (in any base), which does not contain leading zeros." - Wikipedia, which agrees with my opinion, but that doesn't matter anyways as stated above</sub>
  • [JavaScript (Node.js)]: https://nodejs.org
  • [Try it online]: https://tio.run/##RdBPb4IwGAbwu5@CmG1to2v4J9aQkojCYYft4NGZ4Gp1NbUYwGWL4bOzAmXriV95@ubNc95/7UtWiGv1rPIDb1iuyspKaaNodD/mBZQUgFCFko5tx/X8WTAni2W8WifpeKsenWA3kVMVRdRHYcGrW6EsWTfTDc1GttUeGlndx9PIGewY28ZL45lxahwMedvk572D2OS93otFZ3f4v0pN3rY7ewnp7RGntUvIWtsnxO0cJ/FMO8NVIS4Q4fIqRQXBuwII6wqSPfuEUArFUZu@j9q1@p7U7fLBC4taky3GuI0Mj2kE0Nbe7fBRyIoXkOmL/wIBForJ24GXkCGEz7lQEAAU/o3OJccyP8GMf185q6yHezu81tX0JfODvnrZvL3iUi@tTuL4A1PYr4NQnelRNQqbXw "JavaScript (Node.js) – Try It Online"
#4: Post edited by user avatar hydroxyl-radical‭ · 2025-05-27T11:11:23Z (4 days ago)
Ok but it doesn't count as a major change I was just lazy; <s>bytecount</s> won't happen or anything until others actually help me in which case its needed for credit (or something like that)
#3: Post edited by user avatar hydroxyl-radical‭ · 2025-05-27T11:11:10Z (4 days ago)
Ok but it doesn't count as a major change I was just lazy <s>bytecount</s> won't happen or anything until others actually help me in which case its needed for credit (or something like that)
  • # [JavaScript (Node.js)], 62 bytes
  • ```javascript
  • n=>{for(l='';n>0;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}
  • ```
  • [Try it online]!
  • ## Explanation
  • Simple algorithm.
  • ```javascript
  • n=>{for(l='';n>0;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}/*
  • l=''; | ⁡Starting with an empty string...
  • for( n>0; ); | ⁢...loop while n still has hex digits (i.e. nonzero):
  • l="0123456789ABCDEF"[n%16]+l, | ⁣ add the hex digit corresponding to n mod 16
  • n>>=4 | ⁤ then floor division by 16
  • n=>{ return l} | ⁢⁡(in an anonymous arrow function)
  • 💎*/
  • ```
  • Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
  • ## Caveats
  • "It should work at least for all inputs greater than 0 up to the language's default type limit." - the question. (i.e. returning an empty string for 0 is fine) \
  • <sub>"The empty string is a syntactically valid representation of zero in positional notation (in any base), which does not contain leading zeros." - Wikipedia, which agrees with my opinion, but that doesn't matter anyways as stated above</sub>
  • [JavaScript (Node.js)]: https://nodejs.org
  • [Try it online]: https://tio.run/##RdBPb4IwGAbwu5@iMdvaRteUPyKGlEQUDjtsB4/OBIfV1dRiAJcths/OCpStJ37l6Zs3z3n/tS@zQlyrZ5UfeJPlqqxAwhrFwvsxL5BkEAYqpIFkY2rZjjvz5v5iGa3WcTLeqkfL203kVIUhc3FQ8OpWKCDrZrph6YiC9rAQdB9PI2uwZUyNl8Yz48TYG/LU5Oe9vcjknd6LRWd7@L9KTJ7Szk7s93Z8q7Xt@2tt1/ftzlEczbRTUhXigjApr1JUCL4riIkuId5nnwhJoThu0/dRu1bflLpdPngBGJhsCSFtZHjMQoi3dLcjRyErXqBMX/wXCIlQmbwdeIkyjMk5FwpBiIO/0bnkROYnlPLvK88q8HBvh9e6mr5kftBXL5u3V1LqpdVJHH9Qgvp1MK5TParGQfML "JavaScript (Node.js) – Try It Online"
  • # [JavaScript (Node.js)], 60 bytes
  • ```javascript
  • n=>{for(l='';n;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}
  • ```
  • [Try it online]!
  • ## Explanation
  • ```javascript
  • n=>{for(l='';n;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}/*
  • l=''; | ⁡Starting with an empty string...
  • for( n; ); | ⁢...loop while n still has hex digits (i.e. nonzero):
  • l="0123456789ABCDEF"[n%16]+l, | ⁣ add the hex digit corresponding to n mod 16
  • n>>=4 | ⁤ then floor division by 16
  • n=>{ return l} | ⁢⁡(in an anonymous arrow function)
  • 💎*/
  • ```
  • Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
  • ## Caveats
  • "It should work at least for all inputs greater than 0 up to the language's default type limit." - the question. (i.e. returning an empty string for 0 is fine) \
  • <sub>"The empty string is a syntactically valid representation of zero in positional notation (in any base), which does not contain leading zeros." - Wikipedia, which agrees with my opinion, but that doesn't matter anyways as stated above</sub>
  • [JavaScript (Node.js)]: https://nodejs.org
  • [Try it online]: https://tio.run/##RdBPb4IwGAbwu5@CmG1to2v4J9aQkojCYYft4NGZ4Gp1NbUYwGWL4bOzAmXriV95@ubNc95/7UtWiGv1rPIDb1iuyspKaaNodD/mBZQUgFCFko5tx/X8WTAni2W8WifpeKsenWA3kVMVRdRHYcGrW6EsWTfTDc1GttUeGlndx9PIGewY28ZL45lxahwMedvk572D2OS93otFZ3f4v0pN3rY7ewnp7RGntUvIWtsnxO0cJ/FMO8NVIS4Q4fIqRQXBuwII6wqSPfuEUArFUZu@j9q1@p7U7fLBC4taky3GuI0Mj2kE0Nbe7fBRyIoXkOmL/wIBForJ24GXkCGEz7lQEAAU/o3OJccyP8GMf185q6yHezu81tX0JfODvnrZvL3iUi@tTuL4A1PYr4NQnelRNQqbXw "JavaScript (Node.js) – Try It Online"
#2: Post edited by user avatar hydroxyl-radical‭ · 2025-05-27T11:09:09Z (4 days ago)
Syntax highlight right
  • # [JavaScript (Node.js)], 62 bytes
  • ```javascript
  • n=>{for(l='';n>0;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}
  • ```
  • [Try it online]!
  • ## Explanation
  • Simple algorithm.
  • ```
  • n=>{for(l='';n>0;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}/*
  • l=''; | ⁡Starting with an empty string...
  • for( n>0; ); | ⁢...loop while n still has hex digits (i.e. nonzero):
  • l="0123456789ABCDEF"[n%16]+l, | ⁣ add the hex digit corresponding to n mod 16
  • n>>=4 | ⁤ then floor division by 16
  • n=>{ return l} | ⁢⁡(in an anonymous arrow function)
  • 💎*/
  • ```
  • Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
  • ## Caveats
  • "It should work at least for all inputs greater than 0 up to the language's default type limit." - the question. (i.e. returning an empty string for 0 is fine) \
  • <sub>"The empty string is a syntactically valid representation of zero in positional notation (in any base), which does not contain leading zeros." - Wikipedia, which agrees with my opinion, but that doesn't matter anyways as stated above</sub>
  • [JavaScript (Node.js)]: https://nodejs.org
  • [Try it online]: https://tio.run/##RdBPb4IwGAbwu5@iMdvaRteUPyKGlEQUDjtsB4/OBIfV1dRiAJcths/OCpStJ37l6Zs3z3n/tS@zQlyrZ5UfeJPlqqxAwhrFwvsxL5BkEAYqpIFkY2rZjjvz5v5iGa3WcTLeqkfL203kVIUhc3FQ8OpWKCDrZrph6YiC9rAQdB9PI2uwZUyNl8Yz48TYG/LU5Oe9vcjknd6LRWd7@L9KTJ7Szk7s93Z8q7Xt@2tt1/ftzlEczbRTUhXigjApr1JUCL4riIkuId5nnwhJoThu0/dRu1bflLpdPngBGJhsCSFtZHjMQoi3dLcjRyErXqBMX/wXCIlQmbwdeIkyjMk5FwpBiIO/0bnkROYnlPLvK88q8HBvh9e6mr5kftBXL5u3V1LqpdVJHH9Qgvp1MK5TParGQfML "JavaScript (Node.js) – Try It Online"
  • # [JavaScript (Node.js)], 62 bytes
  • ```javascript
  • n=>{for(l='';n>0;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}
  • ```
  • [Try it online]!
  • ## Explanation
  • Simple algorithm.
  • ```javascript
  • n=>{for(l='';n>0;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}/*
  • l=''; | ⁡Starting with an empty string...
  • for( n>0; ); | ⁢...loop while n still has hex digits (i.e. nonzero):
  • l="0123456789ABCDEF"[n%16]+l, | ⁣ add the hex digit corresponding to n mod 16
  • n>>=4 | ⁤ then floor division by 16
  • n=>{ return l} | ⁢⁡(in an anonymous arrow function)
  • 💎*/
  • ```
  • Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
  • ## Caveats
  • "It should work at least for all inputs greater than 0 up to the language's default type limit." - the question. (i.e. returning an empty string for 0 is fine) \
  • <sub>"The empty string is a syntactically valid representation of zero in positional notation (in any base), which does not contain leading zeros." - Wikipedia, which agrees with my opinion, but that doesn't matter anyways as stated above</sub>
  • [JavaScript (Node.js)]: https://nodejs.org
  • [Try it online]: https://tio.run/##RdBPb4IwGAbwu5@iMdvaRteUPyKGlEQUDjtsB4/OBIfV1dRiAJcths/OCpStJ37l6Zs3z3n/tS@zQlyrZ5UfeJPlqqxAwhrFwvsxL5BkEAYqpIFkY2rZjjvz5v5iGa3WcTLeqkfL203kVIUhc3FQ8OpWKCDrZrph6YiC9rAQdB9PI2uwZUyNl8Yz48TYG/LU5Oe9vcjknd6LRWd7@L9KTJ7Szk7s93Z8q7Xt@2tt1/ftzlEczbRTUhXigjApr1JUCL4riIkuId5nnwhJoThu0/dRu1bflLpdPngBGJhsCSFtZHjMQoi3dLcjRyErXqBMX/wXCIlQmbwdeIkyjMk5FwpBiIO/0bnkROYnlPLvK88q8HBvh9e6mr5kftBXL5u3V1LqpdVJHH9Qgvp1MK5TParGQfML "JavaScript (Node.js) – Try It Online"
#1: Initial revision by user avatar hydroxyl-radical‭ · 2025-05-27T11:08:25Z (4 days ago)
# [JavaScript (Node.js)], 62 bytes

```javascript
n=>{for(l='';n>0;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}
```

[Try it online]!

## Explanation

Simple algorithm.

```
n=>{for(l='';n>0;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}/*
        l='';                                                     | ⁡Starting with an empty string...
    for(     n>0;                                  );             | ⁢...loop while n still has hex digits (i.e. nonzero):
                 l="0123456789ABCDEF"[n%16]+l,                    | ⁣    add the hex digit corresponding to n mod 16
                                              n>>=4               | ⁤    then floor division by 16
n=>{                                                 return l}    | ⁢⁡(in an anonymous arrow function)
💎*/
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).

## Caveats

"It should work at least for all inputs greater than 0 up to the language's default type limit." - the question. (i.e. returning an empty string for 0 is fine) \
<sub>"The empty string is a syntactically valid representation of zero in positional notation (in any base), which does not contain leading zeros." - Wikipedia, which agrees with my opinion, but that doesn't matter anyways as stated above</sub>

[JavaScript (Node.js)]: https://nodejs.org
[Try it online]: https://tio.run/##RdBPb4IwGAbwu5@iMdvaRteUPyKGlEQUDjtsB4/OBIfV1dRiAJcths/OCpStJ37l6Zs3z3n/tS@zQlyrZ5UfeJPlqqxAwhrFwvsxL5BkEAYqpIFkY2rZjjvz5v5iGa3WcTLeqkfL203kVIUhc3FQ8OpWKCDrZrph6YiC9rAQdB9PI2uwZUyNl8Yz48TYG/LU5Oe9vcjknd6LRWd7@L9KTJ7Szk7s93Z8q7Xt@2tt1/ftzlEczbRTUhXigjApr1JUCL4riIkuId5nnwhJoThu0/dRu1bflLpdPngBGJhsCSFtZHjMQoi3dLcjRyErXqBMX/wXCIlQmbwdeIkyjMk5FwpBiIO/0bnkROYnlPLvK88q8HBvh9e6mr5kftBXL5u3V1LqpdVJHH9Qgvp1MK5TParGQfML "JavaScript (Node.js) – Try It Online"