Re: How to get left most 8 bit's value from a 32 bit integer ?

2020-01-05 Thread kcvinu
Thank you for the detailed reply.

Re: How to get left most 8 bit's value from a 32 bit integer ?

2020-01-03 Thread Stefan_Salewski
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

Re: How to get left most 8 bit's value from a 32 bit integer ?

2020-01-03 Thread kcvinu
Thanks for the reply. Well, array of bytes is a good idea. Is there any speed penalty in that method ?

Re: How to get left most 8 bit's value from a 32 bit integer ?

2020-01-02 Thread Stefan_Salewski
> 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

Re: How to get left most 8 bit's value from a 32 bit integer ?

2020-01-02 Thread kcvinu
Thank you miran.

Re: How to get left most 8 bit's value from a 32 bit integer ?

2020-01-02 Thread kcvinu
Thank you b3liever, Though, i did not understand what is happening there, that template worked.

Re: How to get left most 8 bit's value from a 32 bit integer ?

2020-01-02 Thread miran
I would do bitmasking + bitshifting: let a = 0b1100_0101 let a_high = (a and 0b_0) shr 4 echo a_high # => 12 (0b1100) Run

Re: How to get left most 8 bit's value from a 32 bit integer ?

2020-01-02 Thread b3liever
like [that](https://github.com/nim-lang/Nim/blob/devel/lib/pure/colors.nim#L28-L31)

How to get left most 8 bit's value from a 32 bit integer ?

2020-01-02 Thread kcvinu
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 ?