c++ - How to loop hex in Javascript? -
in c, output expect. in javascript, output not expect. in javascript, hex loops in decimal not in hexadecimal.
c:
#include<stdio.h> int main(){ for(int i=0x1000;i<=0x109f;i++){ printf("%x\n",i); } return 0; }
javascript:
<script type="text/javascript"> for(var i=0x1000;i<=0x109f;i++){ document.write(i+"<br>"); } </script>
you can use tostring
method:
document.write(i.tostring(16)+"<br>"); //base 16 (hex)
Comments
Post a Comment