Thank you for the detailed reply.
The optimizing C compiler generates generally very good code for all the cases,
but when you really need utmost performance you may inspect the generated
assembler code. The cast to array may be a good solution when you need indeed
bytes as result, but when you need ints as result, only with the
Thanks for the reply. Well, array of bytes is a good idea. Is there any speed
penalty in that method ?
> i did not understand what is happening there,
There is nothing special. First it has not to be a template, a proc would do.
And you have to know only masking and shifting. You shift the bits right, and
then mask all but the lower 8 bits. Same as in C. Another way is casting to
array of bytes
Thank you miran.
Thank you b3liever, Though, i did not understand what is happening there, that
template worked.
I would do bitmasking + bitshifting:
let a = 0b1100_0101
let a_high = (a and 0b_0) shr 4
echo a_high # => 12 (0b1100)
Run
like
[that](https://github.com/nim-lang/Nim/blob/devel/lib/pure/colors.nim#L28-L31)
Hi all, I have 32 bit integer value and i need to get left most 8 bit from it.
Not only left most, actually, i need first 8 bit, then second 8 bit, then third
8 bit. How do i get this ?