Writing an integer in base 2, 8 or 16

### 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:

- a number in base 2 by prefixing it with 0b; the remaining digits have to be 0 or 1.
- an octal number by prefixing it with 0 or 0o; the remaining digits have to be 0-7 since it is base 8.
- a hexadecimal number by prefixing it with 0x; the remaining digits have to be 0-9 or A-F (where A is 10, B is 11, …, F is 15). Non-capital letters a-f are allowed to be used instead.

#### 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 |  |  |  |  |  |  |  |  |  |