text-to-binary
Convert text to binary code or decode binary back to text using this IT tool. Ideal for encoding messages, data processing, or understanding binary representations.
Instructions
Convert text to binary and vice versa
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | Text to convert to binary, or binary to convert to text | |
| operation | Yes | Operation: encode text to binary or decode binary to text |
Implementation Reference
- src/tools/encoding/convert_text_to_binary/index.ts:4-63 (registration)Registration of the "convert_text_to_binary" tool (matches text-to-binary functionality) via exported register function called dynamically from src/index.tsexport function registerConvertTextBinary(server: McpServer) { server.registerTool("convert_text_to_binary", { description: "Convert text to binary and vice versa", inputSchema: { input: z.string().describe("Text to convert to binary, or binary to convert to text"), operation: z.enum(["encode", "decode"]).describe("Operation: encode text to binary or decode binary to text"), }, // VS Code compliance annotations annotations: { title: "Convert Text To Binary", description: "Convert text to binary and vice versa", readOnlyHint: false } }, async ({ input, operation }) => { try { if (operation === "encode") { const binary = input .split('') .map(char => char.charCodeAt(0).toString(2).padStart(8, '0')) .join(' '); return { content: [ { type: "text", text: `Text: ${input} Binary: ${binary}`, }, ], }; } else { // Decode binary to text const binaryGroups = input.replace(/\s+/g, ' ').trim().split(' '); const text = binaryGroups .map(binary => String.fromCharCode(parseInt(binary, 2))) .join(''); return { content: [ { type: "text", text: `Binary: ${input} Text: ${text}`, }, ], }; } } catch (error) { return { content: [ { type: "text", text: `Error converting text/binary: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], }; } } ); }
- Handler function implementing text to binary encoding (splits chars to 8-bit binary strings separated by space) and binary to text decoding.}, async ({ input, operation }) => { try { if (operation === "encode") { const binary = input .split('') .map(char => char.charCodeAt(0).toString(2).padStart(8, '0')) .join(' '); return { content: [ { type: "text", text: `Text: ${input} Binary: ${binary}`, }, ], }; } else { // Decode binary to text const binaryGroups = input.replace(/\s+/g, ' ').trim().split(' '); const text = binaryGroups .map(binary => String.fromCharCode(parseInt(binary, 2))) .join(''); return { content: [ { type: "text", text: `Binary: ${input} Text: ${text}`, }, ], }; } } catch (error) { return { content: [ { type: "text", text: `Error converting text/binary: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], }; } }
- Zod input schema for the tool: 'input' (string) and 'operation' (enum: encode/decode).inputSchema: { input: z.string().describe("Text to convert to binary, or binary to convert to text"), operation: z.enum(["encode", "decode"]).describe("Operation: encode text to binary or decode binary to text"), },