C
C
CodeOfYourLIfe2019-03-21 11:56:41
C++ / C#
CodeOfYourLIfe, 2019-03-21 11:56:41

How to limit bit shifting?

volatile u8 m_d[]={0,0,0,0b00100,0,0,0};
case 4: while(i<7){
if (m_d[i] > 0)
{
m_d[i] = (m_d[i]<<1);
}
i++;
}
I need to persuvate 1 to the least significant bit when it goes out of bounds

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2019-03-21
@CodeOfYourLIfe

Do you need a cyclic shift?
You will have to implement it yourself - just check the last bit before the shift, if it is 1, then add 1 to the number after the shift.

if(m_d[i] & 0x80) {
  m_d[i] = (m_d[i]<<1);
  ++m_d[i];
} else {
  m_d[i] = (m_d[i]<<1);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question