Byte Extensions - AndrzejKebab/UtilityLibrary GitHub Wiki
This utility library provides extension methods for byte operations, allowing you to perform various checks and conversions on byte values.
Calculates the percentage of a byte value relative to another byte value.
byte part = // initialize your byte value;
byte whole = // initialize your byte value;
float percentage = part.PercentageOf(whole);Parameters:
-
part: The byte value for which the percentage is calculated. -
whole: The byte value representing the whole or total.
Returns:
-
percentage: Afloatvalue representing the percentage of thepartrelative to thewhole.
Checks if a byte value is even.
using UtilityLibrary.Core;
byte value = 4;
bool isEven = value.IsEven();-
value(byte): The byte value to check.
- bool:
trueif the byte value is even; otherwise,false.
Checks if a byte value is odd.
using UtilityLibrary.Core;
byte value = 5;
bool isOdd = value.IsOdd();-
value(byte): The byte value to check.
- bool:
trueif the byte value is odd; otherwise,false.
Converts a byte array to an integer.
using UtilityLibrary.Core;
byte[] bytes = { 0, 0, 0, 42 };
int intValue = bytes.ToInt();-
bytes(byte[]): The byte array to convert. -
startIndex(int, optional): The starting index in the byte array. Defaults to 0.
- int: The integer value converted from the byte array.
Converts a byte array to a long integer.
using UtilityLibrary.Core;
byte[] bytes = { 0, 0, 0, 0, 0, 0, 0, 42 };
long longValue = bytes.ToLong();-
bytes(byte[]): The byte array to convert. -
startIndex(int, optional): The starting index in the byte array. Defaults to 0.
- long: The long integer value converted from the byte array.
Converts a byte array to a character.
using UtilityLibrary.Core;
byte[] bytes = { 65 };
char charValue = bytes.ToChar();-
bytes(byte[]): The byte array to convert. -
startIndex(int, optional): The starting index in the byte array. Defaults to 0.
- char: The character value converted from the byte array.
Converts a byte array to a single-precision floating-point number.
using UtilityLibrary.Core;
byte[] bytes = { 0, 0, 0, 42 };
float floatValue = bytes.ToFloat();-
bytes(byte[]): The byte array to convert. -
startIndex(int, optional): The starting index in the byte array. Defaults to 0.
- float: The float value converted from the byte array.
Converts a byte array to a double-precision floating-point number.
using UtilityLibrary.Core;
byte[] bytes = { 0, 0, 0, 0, 0, 0, 0, 42 };
double doubleValue = bytes.ToDouble();-
bytes(byte[]): The byte array to convert. -
startIndex(int, optional): The starting index in the byte array. Defaults to 0.
- double: The double value converted from the byte array.
Converts a byte array to a boolean value.
using UtilityLibrary.Core;
byte[] bytes = { 1 };
bool booleanValue = bytes.ToBoolean();-
bytes(byte[]): The byte array to convert. -
startIndex(int, optional): The starting index in the byte array. Defaults to 0.
- bool: The boolean value converted from the byte array.
Converts a byte array to a hexadecimal string.
using UtilityLibrary.Core;
byte[] bytes = { 10, 20, 30 };
string stringValue = bytes.ToString();-
bytes(byte[]): The byte array to convert. -
startIndex(int, optional): The starting index in the byte array. Defaults to 0.
- string: The hexadecimal string representation of the byte array.
Converts a byte array to a specified type.
using UtilityLibrary.Core;
byte[] bytes = { /* ... */ };
SomeType result = bytes.ToType<SomeType>();-
bytes(byte[]): The byte array to convert.
- T: The object of the specified type converted from the byte array.