# Difference between revisions of "UNSIGNED"

imported>Clippy m |
imported>Clippy m |
||

Line 1: | Line 1: | ||

− | {{ | + | {{DISPLAYTITLE:_UNSIGNED}} |

+ | [[_UNSIGNED]] defines a numerical value as being positive using '''QB64''' only. | ||

Line 60: | Line 61: | ||

{{OutputEnd}} | {{OutputEnd}} | ||

− | ''Explanation:'' The maximum value can only be 65535(32767 + 32768) so the FOR loop repeats itself. Remove the | + | ''Explanation:'' The maximum value can only be 65535(32767 + 32768) so the FOR loop repeats itself. Remove the [[_UNSIGNED]] parts and run it again. |

## Revision as of 20:37, 21 July 2013

_UNSIGNED defines a numerical value as being positive using **QB64** only.

*TYPE* == Syntax ==

*_DEFINE* == Syntax ==

## Description

- When _UNSIGNED values use negative values the result subtracts from the highest value of the number's type keeping it positive.
- Datatype can be any of the following: INTEGER, LONG, _BIT, _BYTE, _INTEGER64, _OFFSET
**SINGLE, DOUBLE and _FLOAT variable types cannot be _UNSIGNED!**- _UNSIGNED can be used in a _DEFINE statement to set undefined variable name first letters as all positive only values.
- Can also be used in DIM statements or Subprocedure parameter definitions following AS.
- _UNSIGNED allows larger positive numerical variable value limits than signed ones.
- The Unsigned variable type suffix used is the
**tilde ~**before the number's own type suffix: variablename~&

00000001 - unsigned & signed are both 1 01111111 - unsigned & signed are both 127 11111111 - unsigned is 255 but signed is -1 11111110 - unsigned is 254 but signed is -2 11111101 - unsigned is 253 but signed is -3

*Example:* Demonstrating how _UNSIGNED variables expand the Integer range.

DIM n AS _UNSIGNED INTEGER DIM pn AS _UNSIGNED INTEGER LOCATE 3, 6: PRINT "Press Esc to exit loop" FOR n = 1 TO 80000 _LIMIT 10000 ' 6.5 second loop LOCATE 12, 37: PRINT n ' display current value IF n > 0 THEN pn = n ' find highest value IF n = 0 THEN Count = Count + 1: LOCATE 14, 37: PRINT "Count:"; Count; "Max:"; pn IF INP(&H60) = 1 THEN EXIT FOR ' escape key exit NEXT n END

Press Esc to exit loop 65462 Count: 13 Max: 65535

*Explanation:* The maximum value can only be 65535(32767 + 32768) so the FOR loop repeats itself. Remove the _UNSIGNED parts and run it again.

## See also

*Navigation:*