fork(2) download
  1. using System;
  2.  
  3. public class OctetString
  4. {
  5. private byte[] m_bDataArray = null;
  6.  
  7. public OctetString(byte[] data_i)
  8. {
  9. //copy input data
  10. m_bDataArray = new byte[data_i.Length];
  11. data_i.CopyTo(m_bDataArray, 0);
  12. }
  13.  
  14. //...
  15. //checks if a bit on a specfied position is set
  16. public bool CheckIfBitOnPositionIsSet(int iPosition)
  17. {
  18. if (m_bDataArray.Length * 8 < iPosition)
  19. {
  20. return false;
  21. }
  22.  
  23. int iByte = iPosition / 8;
  24.  
  25. int iBit = iPosition % 8;
  26.  
  27. byte bData = m_bDataArray[iByte];
  28.  
  29. if((bData & (0x1 << iBit)) != 0)
  30. {
  31. return true;
  32. }
  33. else
  34. {
  35. return false;
  36. }
  37. }
  38. }
  39.  
  40. public class Test
  41. {
  42. public static void Main()
  43. {
  44. byte[] data = { 0xFF, 0x3F, 0x00 };
  45. OctetString octetString = new OctetString(data);
  46. bool isSet = octetString.CheckIfBitOnPositionIsSet(15);
  47. System.Console.Out.WriteLine("{0:d}", isSet);
  48. }
  49. }
Success #stdin #stdout 0.02s 33872KB
stdin
Standard input is empty
stdout
False