What is conceptually happening in this modulation function? I know this is a programming question but i am trying to understand the logic of this. I have come across below function which is basically written in the groovy, which i think is BPSK modulation function.
private final int SAMPLES_PER_SYMBOL = 150
private final float NFREQ = 1/15

private float[] bytes2signal(byte[] buf) {
  float[] signal = new float[buf.length * 8 * SAMPLES_PER_SYMBOL * 2]   // 8 bits/byte, 2 floats/sample
  int p = 0
  for (int i = 0; i &lt; buf.length; i++) {
    for (int j = 0; j &lt; 8; j++) {         // Not sure what is the significant of this ?
      int bit = (buf[i] &gt;&gt; j) &amp; 0x01      // Not sure what is the significant of this ?
      float f = bit == 1 ? -NFREQ : NFREQ 
      for (int k = 0; k &lt; SAMPLES_PER_SYMBOL; k++) {
        signal[p++] = (float)Math.cos(2 * Math.PI * f * k)
        signal[p++] = (float)Math.sin(2 * Math.PI * f * k)
      }
    }
  }
  return signal
}

My question is what is significant of this two lines?
 for (int j = 0; j &lt; 8; j++) {         // Not sure what is the significant of this ?
    int bit = (buf[i] &gt;&gt; j) &amp; 0x01     // Not sure what is the significant of this ?

Can someone please explain this to me ? What is logically happening with this buffer shifting by 8 bit and And-ing with 0x01. Below is the test function for iteration i=0
------------------------------------------------------------
i = 0
j = 0
1 &gt;&gt; 0 = 1
1 &amp; 0x01 = 1
f = -0.06666666666666667
------------------------------
j = 1
1 &gt;&gt; 1 = 0
0 &amp; 0x01 = 0
f = 0.06666666666666667
------------------------------
j = 2
1 &gt;&gt; 2 = 0
0 &amp; 0x01 = 0
f = 0.06666666666666667
------------------------------
j = 3
1 &gt;&gt; 3 = 0
0 &amp; 0x01 = 0
f = 0.06666666666666667
------------------------------
j = 4
1 &gt;&gt; 4 = 0
0 &amp; 0x01 = 0
f = 0.06666666666666667
------------------------------
j = 5
1 &gt;&gt; 5 = 0
0 &amp; 0x01 = 0
f = 0.06666666666666667
------------------------------
j = 6
1 &gt;&gt; 6 = 0
0 &amp; 0x01 = 0
f = 0.06666666666666667
------------------------------
j = 7
1 &gt;&gt; 7 = 0
0 &amp; 0x01 = 0
f = 0.06666666666666667
------------------------------
------------------------------------------------------------
My question is what is significant of this two lines

The code receives a buffer of bytes but the modulation is based on a stream of bits. The outer loop loops over all bytes in the buffer. The
 for (int j = 0; j &lt; 8; j++) {  

This loops over all 8 bits in the current byte
int bit = (buf[i] &gt;&gt; j) &amp; 0x01  

This tests whether the j'th bit in the current byte is 1 on 0, where j = 0 produces the LSb and j = 7 produces the MSb.
If your current byte is 0b11001001, then the variable &quot;bit&quot; will be 1, 0, 0, 1, 0, 0, 1, 1 in each of the 8 loop iterations. Depending whether the current bit is 1 or 0, the modulated signal is generated in phase or out of phase.