Rexx 程式設計/Rexx 入門/數字
外觀
在 Rexx 中,變數是無型別的,被視為可變長度的字串。當一個數字被賦值給一個變數時,代表該數字的字串將被儲存在變數中。在 Rexx 中,數字只是一個或多個數字組成的字串,可以選擇帶一個小數點。
數字可以使用多種常見的記法來表示。
整數是一個正數或負數的整數,沒有小數部分。在 Rexx 中,我們寫整數的方式與日常生活中寫整數的方式非常相似,即一個數字序列,前面可以選擇加一個正號或負號。
/* Here are some positive integers. */ a = 5135 b = 51 c = +6 /* Here are some negative integers. */ d = -5 e = -573 /* The answer on the screen will be 46 */ say d+b
Rexx 數字也可以使用小數點表示小數部分。
pi = 3.14159 centimeters_per_foot = 30.48 absolute_zero = -273.15
指數浮點數可以用科學計數法或工程計數法表示。預設的浮點數表示法是科學計數法。
parse numeric my_numeric_settings say my_numeric_settings 9 0 SCIENTIFIC
預設情況下,數字以十進位制(十進位制)表示。在 Rexx 中,可以用其他進製表示數字。
Rexx 有內建函式可以將十進位制數從二進位制轉換為十六進位制,十六進位制轉換為十進位制,十進位制轉換為十六進位制,以及十六進位制轉換為二進位制。
dec# = 4093 bin# = 1011 hex# = 7ac0 say d2x(dec#) /* decimal to hex */ say x2b(hex#) /* hex to binary */ say x2d(hex#) /* hex to decimal */ say b2x(bin#) /* binary to hex */ say x2d(b2x(bin#)) /* binary to decimal */