number_base_convert
Convert numbers between binary, octal, decimal, hexadecimal, or any base from 2 to 36. Specify the source and target bases to transform numerical values for programming, mathematics, or data analysis applications.
Instructions
Convert a number between different bases (binary, octal, decimal, hexadecimal, or any base 2-36).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| value | Yes | The number string to convert | |
| from_base | No | Source base (2-36, default: 10) | |
| to_base | No | Target base (2-36, default: 16) |
Implementation Reference
- src/tools/converters.ts:99-162 (handler)The tool 'number_base_convert' is registered and implemented within the same `server.tool` call in `src/tools/converters.ts`.
server.tool( "number_base_convert", "Convert a number between different bases (binary, octal, decimal, hexadecimal, or any base 2-36).", { value: z.string().describe("The number string to convert"), from_base: z .number() .int() .min(2) .max(36) .default(10) .describe("Source base (2-36, default: 10)"), to_base: z .number() .int() .min(2) .max(36) .default(16) .describe("Target base (2-36, default: 16)"), }, async ({ value, from_base, to_base }) => { try { const decimal = parseInt(value, from_base); if (isNaN(decimal)) { return { content: [ { type: "text" as const, text: `Error: '${value}' is not a valid base-${from_base} number`, }, ], isError: true, }; } const result = { input: value, from_base, to_base, result: decimal.toString(to_base).toUpperCase(), decimal: decimal, binary: decimal.toString(2), octal: decimal.toString(8), hex: decimal.toString(16).toUpperCase(), }; return { content: [ { type: "text" as const, text: JSON.stringify(result, null, 2) }, ], }; } catch (e) { return { content: [ { type: "text" as const, text: `Error: ${e instanceof Error ? e.message : String(e)}`, }, ], isError: true, }; } } );