fork download
  1. // Converts an array of bytes into an int.
  2. unsafe public static int ToInt32(byte[] value, int startIndex)
  3. {
  4. if (value == null) {
  5. ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
  6. }
  7.  
  8. if ((uint)startIndex >= value.Length) {
  9. ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
  10. }
  11.  
  12. if (startIndex > value.Length - 4) {
  13. ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
  14. }
  15.  
  16. fixed (byte* pbyte = &value[startIndex]) {
  17. if (startIndex % 4 == 0) {
  18. // data is aligned
  19. return *((int*)pbyte);
  20. }
  21. else {
  22. if (IsLittleEndian) {
  23. return (*pbyte) | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24);
  24. }
  25. else {
  26. return (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3));
  27. }
  28. }
  29. }
  30. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty