Previous Up Next

5.4.1  Writing an integer in base 2, 8 or 16

Integers are typically entered and displayed in base 10. You can also enter an integer in base 2 (binary), base 8 (octal) or base 16 (hexadecimal). You can enter:

Examples

Since 101 in binary is the same as 1· 1+0· 2+1· 22=5 in decimal:

0b101
     
5           

Since 512 in base 8 is the same as 2· 1+1· 8+5· 82=330 in decimal:

0512
     
330           

Since 2F3 in base 16 is the same as 3· 1+15· 16+2· 162=755 in decimal:

0x2F3
     
755           

You can have Xcas print integers in octal or hexadecimal, as well as the default decimal. To change the base used for display, you can click on the red CAS status button and choose from the Integer basis menu (see Section 2.5.7, item 2.5.7). If you have Xcas set to display in hexadecimal, you will get the following:

15
     
0xF           
0x15
     
0x15           

Previous Up Next