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, &t); if (ret != 0) fatal_error("clock_gettime failed", 0); return (uint64_t)t.tv_sec * 1000000000 + t.tv_nsec; } On Fri, Jun 5, 2020 at 5:00 PM Doug Coleman <doug.cole...@gmail.com> 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 > > 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 power of 8 bits or a power of two > bytes. > > USE: math.bitwise > nano-count dup dup log2 1 + bits = > > On Fri, Jun 5, 2020 at 4:44 PM Alexander Ilin <ajs...@yandex.ru> wrote: > >> 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 >> `byte-array` there are `>le` and `>be`, but they require the number of >> bytes as a parameter. The question is, what should I supply for the value >> received from `nano-count`? >> >> And the bigger question is, given an integer value, is there a way to >> interrogate it about its byte size, i.e. the minimum number of bytes it >> takes to hold the value without truncation and without leading zeroes: >> >> Value -- MinSize >> 0 -- 1 >> 255 -- 1 >> 256 -- 2 >> 65535 -- 2 >> 65536 -- 3 >> etc. >> >> I would expect such information to be available somewhere without doing >> the power of two calculations in a loop. >> >> 23.03.2020, 05:41, "Doug Coleman" <doug.cole...@gmail.com>: >> >> For Factor, integers are either fixnum or bignum size. For C, you tell it >> how many bytes it occupies according to the C header. Generally the sizes >> are the same across platforms. If they aren't, you might need two different >> STRUCT: declarations like in basis/unix/stat/linux/32/32.factor >> and basis/unix/stat/linux/64/64.factor. >> >> The main point -- function signatures and struct declarations usually >> handle the integer sizes and you shouldn't have to think much about it. Do >> you have a specific example? >> >> >> >> >> Earlier I wrote: >> >> One more question. I want to convert an integer into a byte-array >> containing its bytes. In my use case it was the return value of the >> nano-count, but the question is general: how can I get the bytes of an >> integer. >> >> For floats there are primitives like float>bits and double>bits, and for >> integers there is >le and >be, but for the latter two I need to specify the >> size in bytes. Is there a way to ask an integer how many bytes it occupies? >> Because from the documentation it's not clear at all how many bytes >> nano-count would return, and it may vary depending on the current platform. >> What am I missing? >> >> _______________________________________________ >> Factor-talk mailing list >> Factor-talk@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/factor-talk >> >
_______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk