Short & Word Functions

Purpose

Sign extension

Syntax

%= Short(m&)

%= Word(m&)

%: 32-bit long word expression
m&: 16-bit word expression

Description

Extends a Word to a Long word. An And 65535 ($0000FFFF) is performed first on the Word. If the result is greater than 32767 (bit 15 is set), 65535 is subtracted from it. This is equivalent to copying the value of bit 15 to bits 16 to 31.

Example

AutoRedraw = 1

FontName = "Courier"

Local s% = 32, m% = 2096, a As Double = 100000

Print Bin(m%, s%)                       // 00000000000000000000100000110000

Print Bin(Word(m%), s%)                 // 00000000000000000000100000110000

Print String(s%, "-")                   // --------------------------------

Print Bin(a, s%)                        // 00000000000000011000011010100000

Print Bin(Word(a), s%)                  // 11111111111111111000011010100000

Print Bin((a And 65535) - 65536, s%)    // 11111111111111111000011010100000

Print Bin((a Mod 65536) - 65536, s%)    // 11111111111111111000011010100000

Print Word(a)                           // -31072

Remarks

These functions load the value into the eax register and performs a CDWE assembler instruction to extend the lower 16 bits to the upper 16 bits.

See Also

Byte(), Card(), SWord, UShort(), UWord()

{Created by Sjouke Hamstra; Last updated: 04/03/2017 by James Gaite}