Glenn Patton

Glenn Patton

  • NA
  • 308
  • 82.7k

Swapping order of bits:

Jan 24 2013 9:21 AM

Hi All,

I have a problem reading back some data from a device, I get back a string "19000000" this string needs to be in the order "00000019" ie reversed but
as it is a string of data it needs to be ordered differently from the obvious reversal method  if you follow me 

 bit heading      87 65 43 21 
returned          19 00 00 00

order wanted   00 00 00 19  
bit heading      21 43 65 87


I have done the following:

for (int i = 0; i <= value_split.Length; i += 2)

{

if (i == value_split.Length)

{

break;

}

Credit_Value_Correct[a] += value_split.Substring(i, 2);

a++;

}

textBox1.Text = Credit_Value_Correct[3] + Credit_Value_Correct[2] + Credit_Value_Correct[1] + Credit_Value_Correct[0];

}

While this appears to work is there a better, more proper way of altering the big-endian to little-endian in C#?

Thanks Glenn  



 


 


Answers (2)