Page 68 of 346 Start Back Next End ZBasic System Library 56 ZBasic Microcontrollers CByte Type Function returning Byte Invocation CByte(arg) Parameter Method Type Description arg ByVal numeric, String, Boolean or Enum The value to convert to Byte. Discussion This function converts any numeric or enumeration value to a Byte value. See the table below for details of the conversion. Input Type Result Boolean Returns the byte value of the Boolean data item: 0 or 255. Byte No effect, the value is as supplied. Integer Returns the low byte of the value provided. However, if the supplied value is negative or greater than 255, the returned value will be 255. UnsignedInteger Returns the low byte of the value provided. However, if the supplied value is greater than 255, the returned value will be 255. Enum Returns the low byte of the value provided. However, if the supplied value is greater than 255, the returned value will be 255. Long Returns the low byte of the value provided. However, if the supplied value is negative or greater than 255, the returned value will be 255. UnsignedLong Returns the low byte of the value provided. However, if the supplied value is greater than 255, the returned value will be 255. Single The supplied value is converted to a Long value (signed 32-bit integer), rounded to the nearest integer. If the fractional part is exactly 0.5, the resulting integer will be even. This is known as “statistical rounding”. If the resulting integer value is negative or larger than 255, the result will be 255. Otherwise, the result will be the integral value. String The result is the numeric value of the characters in the string, ignoring leading space and tab characters. The value string may begin with a plus or minus sign and an optional radix indicator (&H for hexadecimal, &O for octal, &B or &X for binary, all case insensitive). The conversion is terminated upon reaching the end of the string or encountering the first character that is not valid for the indicated radix. Compatibility In BasicX, calling CByte() with an UnsignedInteger argument returns the low byte of the value. This behavior is inconsistent with the other type conversions. This implementation attempts to make them consistent.