program SPI

The signals clk and data come, I copy them and output them to neighboring pins
and also output the received value to uart

in theory, everything should work, and in the terminal I should to get
1001100111

I get them, but in time with errors
What could be the problem?

int data = 1; // pin status data
uint16_t b = 0; // the value accepted
unsigned long oldtime; // the last pulse time clk
int flag = 0; // flag that the byte is printed
int i = 8; // bit number for writing

void setup ()
{
  Serial.begin (115200);
  attachInterrupt (0, dataPin2, CHANGE);
  attachInterrupt (1, clkPin3, CHANGE);
  pinMode (6, OUTPUT); // data copy
  pinMode (7, OUTPUT); // clk copy
  b |= (1 « 9); // that would not be missing zeroes forward written 1
}

void loop () {
// if the pack of the impulses ended long ago and the byte was not printed
  if (millis () - oldtime> 5)
  {if (flag == 1)
    {
     // print byte, clear byte, flag and bit counter
     Serial.println (b, BIN);
       b = 0; b |= (1 « 9);    flag = 0;   i = 8;
    }
  }
}

void dataPin2 () {
 // if the value of the pin changes - count and save it
 data = digitalRead (2);
 digitalWrite (6, data); // copying the signal data
}

void clkPin3 () {
// if the value of the pin has changed
// if data = 1 write it to a byte and move the position of the record 1 to the left
// if data = 0 then just move the position of the record 1 to the left
  if (data == 1)
{b |= (1 « i);}
  i = i-1;

  if (i <= 0) {Serial.println ("ERR");}
  
 digitalWrite (7, digitalRead (3)); // copying the clk signal
  oldtime = millis (); // the arrival time of the last impulse clk
  flag = 1; // flag-byte not printed
}

I get them, but in time with errors
What could be the problem?

Clock interrupts?
Serial interrupts?

Whatever, don't do serial output in interrupts.
It says it on the tin.

You are sharing data between the interrupt service routines and loop(), but the variables containing the data are not declared volatile. They MUST be.

These don’t look right

     14:  b |= (1 « 9); // that would not be missing zeroes forward written 1
     24:       b = 0; b |= (1 « 9);    flag = 0;   i = 8;
     40:{b |= (1 « i);}

When did those << become «?

Thanks. finally its working. But still one problem. I want to delete digitalWrite functions. but if I do it - my code can not print true values

int volatile data = 1; // pin status data
uint16_t volatile b = 0; // the value accepted
unsigned long volatile oldtime; // the last pulse time clk
int volatile flag = 0; // flag that the byte is printed
int volatile i = 8; // bit number for writing
int volatile checkbit = 0; // bit number for writing

void setup ()
{
  Serial.begin (115200);
  attachInterrupt (0, dataPin2, CHANGE);
  attachInterrupt (1, clkPin3, CHANGE);
  pinMode (6, OUTPUT); // data copy
  pinMode (7, OUTPUT); // clk copy
  b |= (1 <<  9); // that would not be missing zeroes forward written 1
}

void loop () {
  noInterrupts();
  cli();//Disable interrupts
  // if the pack of the impulses ended long ago and the byte was not printed
  if (millis () - oldtime > 5)
  { if (flag == 1)
    {
      // print byte, clear byte, flag and bit counter
      if (checkbit == 9){
      Serial.println (b, BIN);}
      b = 0; b |= (1 <<  9);    flag = 0;   i = 8; checkbit = 0;
    }
  }
  interrupts();
  sei(); //Enables interrupts
}

void dataPin2 () {
  // if the value of the pin changes - count and save it
  data = digitalRead (2);
  digitalWrite (6, data); // copying the signal data
}

void clkPin3 () {

  checkbit++;
  // if the value of the pin has changed
  // if data = 1 write it to a byte and move the position of the record 1 to the left
  // if data = 0 then just move the position of the record 1 to the left
  if (data == 1)
    {b |= (1 << i);}


  if (i > 0) {
      i = i - 1;
  }

  digitalWrite (7, digitalRead (3)); // copying the clk signal
  oldtime = millis (); // the arrival time of the last impulse clk
  flag = 1; // flag-byte not printed
}
  noInterrupts();
  cli();//Disable interrupts

Which ONE of these methods do you want to use?

  interrupts();
  sei(); //Enables interrupts

Which ONE of these methods do you want to use?

  // if the value of the pin changes - count and save it

Exactly which of those two lines of code does that?