Page 1 of 1

Help me interpret an expression, please

PostPosted: Fri Mar 02, 2012 11:09 am
by jamsoft
Hi all, I'm a beginner in Scheme programming and I don't understand the following expression:

(bitwise-arithmetic-shift #vu8(1 0 0 0) pin) where pin is usually the integer 0 to 31

Can you explain me step by step, what is the purpose of this expression and what is happening inside it, please?

I understand what e.g. (bitwise-arithmetic-shift #xHexNumber) means but I don't understand it in conjunction with the #vu8(1 0 0 0) (byte-vector???) in the above mentioned expression...

Thank you for your help...and please, take into consideration that I'm really a beginner... :-)

Re: Help me interpret an expression, please

PostPosted: Fri Mar 02, 2012 11:16 pm
by saulgoode
#vu8 is merely a way of representing* a bit vector whereby each element of the list of values within the parentheses represents 8-bits of the bit vector. As a binary number, #vu8(1 0 0 0) is equivalent to a "1" followed by 24 zeros; as a decimal number it is the same as 256*256*256, or 2^24 (16,777,216).

* under the R6RS standard.

Re: Help me interpret an expression, please

PostPosted: Sat Mar 03, 2012 6:57 am
by jamsoft
Thank you very much for your explanation.

So, for confirmation that I've understood well, e.g. - the #vu8(0 0 4 0) - considering that every element of the bit vector is 8-bit number it will be interpreted as 21 zeros followed by 1 and then followed by 10 zeros? (i.e. 00000000000000000000010000000000)?

Am I right?

Re: Help me interpret an expression, please

PostPosted: Sun Mar 04, 2012 2:41 pm
by saulgoode
Yes, I believe your understanding is correct.

Re: Help me interpret an expression, please

PostPosted: Wed Mar 14, 2012 12:27 am
by jamsoft
Thank you! Your explanation helped me very much!