Cast example

Started by Frank Brübach, June 03, 2024, 01:53:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

I dont know If there's any Cast example for oxygen but I noticed its Working perfect with sbyte

'' cast example (freebasic) and oxygen translation
''
uses console

sbyte sb 'signed byte
sb=32.2
print " 32.2 "+sb ' result 32


'' freebasic
'' Print Cast( Byte, &h0080 ) '-128 ''

'' oxygen
''
sb=byte(&h0080)
print " byte ="+sb ' result: -128


'' will print 3 because the floating-point value will be converted to an Integer
'' (this Casting operator is equivalent to using CInt)
''
'' Print Cast( Integer, 3.1 ) '3

'' oxygen
''

sb=integer(3.1)
print " integer 3.1 =" + sb ' result: 3

wait

Charles Pegge

in o2, byte and ubyte are unsigned, sbyte is signed. You can also cast as char:

int a=43
print cast byte a  '43'  same as ubyte
print cast char a  '+'