Skip to content

Add Text/Integer Converter operation#2213

Open
p-leriche wants to merge 1 commit intogchq:masterfrom
p-leriche:string-integer
Open

Add Text/Integer Converter operation#2213
p-leriche wants to merge 1 commit intogchq:masterfrom
p-leriche:string-integer

Conversation

@p-leriche
Copy link

Description

Converts between text strings and large integers (decimal or hexadecimal), interpreting text as big-endian byte sequences.

Changes

  • Add TextIntegerConverter.mjs operation
  • Update Categories.json to include Text/Integer Converter in Data format category

Functionality

Bidirectional conversion between text and numeric representations:

  • Text → Integer: Interprets each character's code as bytes in big-endian order
  • Integer → Text: Decodes integer as big-endian bytes to characters

Examples:

  • "ABC" → 4276803 (decimal) or 0x414243 (hex)
  • 0x48656C6C6F → "Hello"
  • 123456789 → corresponding text representation

Use Cases

  • Cryptographic operations requiring numeric text representations
  • Encoding/decoding text as numeric values
  • Data format conversions
  • Understanding byte-level text encoding

Features

  • Automatic input format detection:
    • Quoted strings ("text" or 'text')
    • Hexadecimal (0x... prefix)
    • Decimal (plain numbers)
    • Unquoted text (treated as string)
  • Output in string, decimal, or hexadecimal format
  • Fully pipeable for use in operation chains
  • Round-trip validation (string→integer→string preserves original)
  • Handles arbitrarily large text using BigInt

Dependencies

Depends on BigIntUtils PR #2205

This operation uses parseBigInt from the shared BigIntUtils library.

Satisfies

Feature Request #2141

This operation uses parseBigInt from the shared BigIntUtils library.

Testing

  • Tested text to decimal conversion
  • Tested text to hexadecimal conversion
  • Tested decimal to text conversion
  • Tested hexadecimal to text conversion
  • Verified round-trip conversions (string→int→string)
  • Tested with quoted and unquoted input
  • Built successfully with npm run build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant