using
System;
using
System.Collections.Generic;
public
class
GFG {
public
static
void
Main()
{
try
{
byte
[] bytes = {0, 128, 63, 0, 0, 112, 65,
0, 255, 127, 71, 0, 0, 128,
59, 0, 0, 128, 47, 73, 70,
131, 5, 75, 6, 158, 63, 24};
Console.Write(
"Initial Array: "
);
PrintIndexAndValues(bytes);
Console.WriteLine(
"index Array elements float values"
);
Console.WriteLine();
for
(
int
index = 0; index < bytes.Length + 1;
index = index + 4) {
if
(index == bytes.Length) {
Console.WriteLine();
Console.WriteLine(
"startIndex is greater than "
+
"the length of bytes minus 1."
);
float
values = BitConverter.ToSingle(bytes, index);
Console.WriteLine(
" {0} {1} {2}"
,
index, BitConverter.ToString(bytes,
index, 4), values);
}
else
{
float
values = BitConverter.ToSingle(bytes, index);
Console.WriteLine(
" {0} {1} {2}"
,
index, BitConverter.ToString(bytes,
index, 4), values);
}
}
}
catch
(ArgumentNullException e) {
Console.Write(
"Exception Thrown: "
);
Console.Write(
"{0}"
, e.GetType(), e.Message);
}
catch
(ArgumentOutOfRangeException e) {
Console.Write(
"Exception Thrown: "
);
Console.Write(
"{0}"
, e.GetType(), e.Message);
}
catch
(ArgumentException e) {
Console.Write(
"Exception Thrown: "
);
Console.Write(
"{0}"
, e.GetType(), e.Message);
}
}
public
static
void
PrintIndexAndValues(
byte
[] myArr)
{
for
(
int
i = 0; i < myArr.Length; i++) {
Console.Write(
"{0} "
, myArr[i]);
}
Console.WriteLine();
Console.WriteLine();
}
}