What does $ with a numeric value mean in Delphi

后端 未结 3 1643
难免孤独
难免孤独 2021-01-18 01:31

What does it means, in Delphi, when I see a command like this:

char($23)

What does the dollar symbol mean in this context?

相关标签:
3条回答
  • 2021-01-18 02:11

    It represents a character. For example char(13) is end of line.

    0 讨论(0)
  • 2021-01-18 02:28

    The dollar symbol represents that the following is a hex value.

    ShowMessage(Char($23)); shows #.

    0 讨论(0)
  • 2021-01-18 02:29

    The $ symbol is used to prefix a hexadecimal literal. The documentation says:

    Numerals

    Integer and real constants can be represented in decimal notation as sequences of digits without commas or spaces, and prefixed with the + or - operator to indicate sign. Values default to positive (so that, for example, 67258 is equivalent to +67258) and must be within the range of the largest predefined real or integer type.

    Numerals with decimal points or exponents denote reals, while other numerals denote integers. When the character E or e occurs within a real, it means "times ten to the power of". For example, 7E2 means 7 * 10^2, and 12.25e+6 and 12.25e6 both mean 12.25 * 10^6.

    The dollar-sign prefix indicates a hexadecimal numeral, for example, $8F. Hexadecimal numbers without a preceding - unary operator are taken to be positive values. During an assignment, if a hexadecimal value lies outside the range of the receiving type an error is raised, except in the case of the Integer (32-bit integer) where a warning is raised. In this case, values exceeding the positive range for Integer are taken to be negative numbers in a manner consistent with two's complement integer representation.

    So, in your example, $23 is the number whose hexadecimal representation is 23. That number has decimal representation 35, so you can write:

    Assert($23 = 35);
    
    0 讨论(0)
提交回复
热议问题