Vorzeichenkonvertierung

ByteToInt16(), WordToInt16(), ByteToInt32(), WordToInt32()

Diese Funktionen konvertieren den Übergabewert explizit in einen vorzeichenbehafteten Wert. Diese Funktion wird benötigt, wenn man beispielsweise einen nicht vorzeichenbehafteten Variablen- oder Rückgabewert Vorzeichenrichtig weiterbearbeiten möchte. Dies ist z.Bsp. der Fall, wenn eine Byte-Variable empfangen worden ist, die statt 0-255 den vorzeichenbehafteten Wertebereich von -127 bis +128 darstellt. Da der Datentyp Byte nicht vorzeichenbehaftet ist, wären Rechnungen und Darstellung damit ebenfalls nicht vorzeichenbehaftet.

Syntax

  • integer = ByteToInt16( value as byte )
  • integer = WordToInt16( value as word )
  • longint = ByteToInt32( value as byte )
  • longint = WordToInt32( value as word )

Beispiel:

const F_CPU=20000000
avr.device = atmega328p
avr.clock  = F_CPU
avr.stack = 64
 
uart.baud = 19200
uart.recv.enable
uart.send.enable
 
dim a as byte
dim b as word
 
a=0xff
b=0xffff
print str(a)                'Ausgabe: "255"
print str(b)                'Ausgabe: "65535"
print str(ByteToInt16(a))   'Ausgabe: "-1"
print str(WordToInt16(b))   'Ausgabe: "-1"