# 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 since it is binary.

#### Example.

Input:

0b101

Output:

5

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

You can enter a number in octal by prefixing it with 0 or 0o; the remaining digits have to be 0 through 7 since it is base 8.

#### Example.

Input:

0512

Output:

330

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

You can enter a number in hexademical by prefixing it with 0x; the remaining digits have to be 0 through 9 or a through f (where a is 10, b is 11, …, f is 15).

#### Example.

Input:

0x2f3

Output:

755

since 2f3 in base 16 is the same as 3· 1 + 15· 16 + 2· 162 = 755 in decimal.

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 14). If you have Xcas set to display in hexadecimal, you will get the following:
Input:

15

Output:

0xF

Input:

0x15

Output:

0x15