Cast -- cast a number to a new signed/unsigned type (V3.0)
result = Cast(val, sign, type)
This function can be used to cast a value to a different type. This is normally not needed in Hollywood because Hollywood only knows one variable type for numbers (all numbers in Hollywood are stored as signed 64-bit floating point values; Hollywood does not differentiate between byte, short, integer, and floating point types internally). Thus, what you receive in result will not really be a variable of the type you have cast it to, but it will just be clipped to the boundaries of the variable type you specify.

However, this function can come in quite handy when it comes to do signed and unsigned conversions. You might want to know which number you get when you want to convert 41234 to a signed short value. You can use this function to do that.

Cast() accepts three arguments: The first argument is the value that shall be cast, the second argument specifies whether or not you want a signed value and must be either True (= cast to signed) or False (= cast to unsigned). The last argument finally specifies the type the value shall be cast to. This can be #INTEGER (32-bit), #SHORT (16-bit) or #BYTE (8-bit).

source value to be cast
True (signed cast) or False (unsigned cast)
destination type for the value (#INTEGER, #SHORT or #BYTE)
result of the cast operation
Print(Cast(41234, TRUE, #SHORT))
The code above casts the number 41234 to a signed short (16-bit) value and prints the result which is -(2^16-41234) = -24302.

Show TOC