I guess you could check if the difference between the current value and the maximum if large enough to do the addition:
var difference = byte.MaxValue - value;
if(difference >= 24)//OK to add 24
else//will cause overflow
To detect underflows you can use the byte.MinValue
value instead:
var difference = value - byte.MinValue;
if(difference >= 24)//OK to subtract 24
else//will cause underflow
With these in mind you could go as far as making some extension methods for them:
public static class OverflowExtensions
{
public static bool WillAdditionOverflow(this byte b, int val)
{
return byte.MaxValue - b < val;
}
public static bool WillSubtractionUnderflow(this byte b, int val)
{
return b - byte.MinValue < val;
}
}
Which you can use like so:
using MyApp.OverflowExtensions;
//...
if(value.WillAdditionOverflow(24))
//value + 24 will cause overflow
if(value.WillSubtractionUnderflow(24))
//value - 24 will cause underflow