Hello Charles, do you know cByte?
Its interesting datatype for oxygen too? Its existing in freebasic as converting Data Type
CBYTE
Converts numeric or string expression to Byte.
Syntax:
declare function Cbyte ( byval expression as datatype ) as byte
Type typename
declare operator cast ( ) as byte
End Type
Usage:
result = Cbyte( numeric expression )
result = Cbyte( string expression )
result = Cbyte( user defined type )
Parameters:
expression
A numeric, string, or pointer expression to cast to a Byte value.
datatype
Any numeric, string, or pointer data type.
typename
A user defined type.
Return Value:
A Byte value.
Description:
The Cbyte function rounds off the decimal part and returns a 8-bit Byte value. The function does not check for an overflow, and results are undefined for values which are less than -128 or larger than 127.
The name can be explained as 'Convert to Byte'.
If the argument is a string expression, it is converted to numeric by using Valint.
Examples:
' Using the CBYTE function to convert a numeric value
'Create an BYTE variable
Dim numeric_value As Byte
'Convert a numeric value
numeric_value = CByte(-66.30)
'Print the result, should return -66
Print numeric_value
Sleep
Hi Frank,
string-to-number conversion etc is built into Oxygen:
sbyte sb 'signed byte
sb=32
print sb
sb=32.6
print sb 'rounds to 33
sb="-32"
print sb 'auto-convert string -32
sb=255
print sb 'wrap overflow -1
Oh good didn't know yet thx Charles
Found an old freebasic examples with cByte(260)=4 and I didnt understand the result but now... ;)
''CodeSelect
sbyte sb 'signed byte
sb=32
print sb
sb=32.6
print sb 'rounds to 33
sb="-32"
print sb 'auto-convert string -32
sb=255
print sb 'wrap overflow -1
' if that's -1 then 260 it's 4 ?
' why it's 4 as result? => 5 - 1 ? = 4
sb=260
print sb ' 4
some signed byte values:
0x7f --> 127
0x80 --> -128
0x81 --> -127
...
0xfe --> -2
0xff --> -1
0x104 modulo 0xff --> 4