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

Reply via email to