Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread John Benediktsson
Log2 is pretty fast. We use BSR if available. https://c9x.me/x86/html/file_module_x86_id_20.html > On Jun 5, 2020, at 3:01 PM, Doug Coleman wrote: > >  > As long as you can fully round-trip the integer, it doesn't matter how many > bytes you use. > > nano-count dup 4 >be be> = . > f >

Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Alexander Ilin
Does it also return 8 bytes in 32-bit Windows? 06.06.2020, 01:09, "Doug Coleman" :Actually, I can be more helpful. ``nano-count`` returns a ``uint64_t`` so you need 8 bytes. In vm/os-genunix.cpp: uint64_t nano_count() {  struct timespec t;  int ret = clock_gettime(CLOCK_MONOTONIC, );  if (ret !=

Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Doug Coleman
Yes, you can see this using ripgrep: ➜ factor-master git:(master) ✗ cd vm ➜ vm git:(master) ✗ rg nano_count os-genunix.cpp 30:uint64_t nano_count() { os-windows.hpp <--- 70:uint64_t nano_count(); os-macosx.mm 77:uint64_t nano_count() { vm.cpp 31:

Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Doug Coleman
Actually, I can be more helpful. ``nano-count`` returns a ``uint64_t`` so you need 8 bytes. In vm/os-genunix.cpp: uint64_t nano_count() { struct timespec t; int ret = clock_gettime(CLOCK_MONOTONIC, ); if (ret != 0) fatal_error("clock_gettime failed", 0); return (uint64_t)t.tv_sec *

Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Alexander Ilin
Nice! I'm also using RipGrep.Thank you! 06.06.2020, 01:37, "Doug Coleman" :Yes, you can see this using ripgrep: ➜  factor-master git:(master) ✗ cd vm➜  vm git:(master) ✗ rg nano_countos-genunix.cpp30:uint64_t nano_count() {os-windows.hpp       <---70:uint64_t

Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Alexander Ilin
Hello again!  My specific example is the following. I want to put the output of `nano-count` into a `byte-array`, which is fed into a hash. The current value of `nano-count` is one of the sources of randomness gathered from the system and poured into the hash. To convert the integer value into a

Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Doug Coleman
As long as you can fully round-trip the integer, it doesn't matter how many bytes you use. nano-count dup 4 >be be> = . f nano-count dup 8 >be be> = . t nano-count dup 128 >be be> = . t ``log2 1 +`` will give you the required number of bits to store an integer. You will want to round up to a