There are a number of notations in the Xojo language that start with “&”, and I thought it would be handy to post them somewhere as reference.
- &b - A binary literal, like &b00001111, as an UInt32.
- &c - A color with RGB + alpha channel values as hex, like &c12ABCDFF, as a Color. (You can leave off the alpha channel, like &c12ABCD.)
- &h - A hexadecimal literal, like &h12AE, as an UInt32.
- &o - An octal literal, like &o777, as an UInt32.
- &u - A Unicode string with the given code point as hex, like &h201C (left double curly quote), as string.
You’d use these as you would any constant. Just type them without quotes in places where you might otherwise use a number, color, or string. For example, these both do exactly the same thing:
n = &b11111111
n = 255
So do these:
s = &u61
s = "a"
You can also use these within a string to convert that string to a number with Val. For example, if you have the string “0A”, you can use this code to convert it to a number:
s = "0A"
n = Val( "&h" + s )
// n = 10
Hope someone finds this useful. Personally, I didn’t know (or remember) about the “&u” notation until Norman posted about it today in another conversation.