VS Code Extensions
Integer Literal Converter

Integer Literal Converter

by srejv

A language-aware VS Code extension for converting integer literals between decimal, hexadecimal, octal, and binary while preserving supported syntax and suffixes.

Downloads

24

Rating

— (0)

Version

0.0.1

Last updated

Apr 09, 2026

Convert the integer literal under the cursor between decimal, hexadecimal, octal, and binary.

This extension is built for language-aware code editing rather than plain text replacement. It preserves the syntax that makes sense for the current file, exposes separate bindable commands for each target base, and includes a cycle command for quick repeated switching.

Features

  • Convert the literal under the cursor directly to decimal, hexadecimal, octal, or binary.
  • Cycle through the supported formats for the current language.
  • Respect language-specific syntax instead of forcing one style everywhere.
  • Preserve supported integer suffixes such as n, U, UL, ULL, and L.
  • Support multi-cursor edits.
  • Show a hover preview with the equivalent literal formats.

Example

Examples of what the commands do:

// C++
493      -> 0755
0755     -> 0b111101101
42U      -> 0x2aU
// TypeScript
10n      -> 0xan
0xan     -> 0o12n
0b1010   -> 10
// Java
42L      -> 0x2aL
0x2aL    -> 052L

Supported Languages

The extension chooses literal syntax based on the active editor language.

Language group Behavior
C and C++ Uses native forms such as 0755, 0b1010, digit separators with ', and suffixes like U, UL, and ULL.
Java Uses native forms such as 0755, _ digit separators, and L suffixes.
C# Uses 0x and 0b forms plus U, L, and UL suffixes. Octal is skipped because C# does not support octal integer literals.
Swift Uses 0o octal syntax and _ separators.
Generic profile Used for languages such as JavaScript and TypeScript. Supports 0x, 0o, 0b, _ separators, and bigint n suffixes.

Commands

All commands are normal VS Code commands, so they can be run from the Command Palette or bound to keys.

Title Command ID
Integer Literal: Convert to Decimal integerLiteral.convertToDecimal
Integer Literal: Convert to Hexadecimal integerLiteral.convertToHexadecimal
Integer Literal: Convert to Octal integerLiteral.convertToOctal
Integer Literal: Convert to Binary integerLiteral.convertToBinary
Integer Literal: Cycle Base integerLiteral.cycleBase

Cycle order follows the formats supported by the current language. In languages with full support, the order is:

decimal -> hexadecimal -> octal -> binary -> decimal

In C#, octal is skipped.

Hover Preview

Hovering an integer literal can show the equivalent forms for that value in the active language syntax.

Examples:

  • C and C++ hovers show native octal like 0755.
  • C# hovers omit octal because the language does not support it.
  • Generic and Swift hovers show 0o octal.

Extension Settings

This extension contributes the following setting:

  • integerLiteral.hover.enabled: Enable or disable hover previews for integer literals. Default: true.

Suggested Keybindings

Example keybindings.json entries:

[
  {
    "key": "ctrl+alt+h",
    "command": "integerLiteral.convertToHexadecimal",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+alt+d",
    "command": "integerLiteral.convertToDecimal",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+alt+o",
    "command": "integerLiteral.convertToOctal",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+alt+b",
    "command": "integerLiteral.convertToBinary",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+alt+c",
    "command": "integerLiteral.cycleBase",
    "when": "editorTextFocus"
  }
]

Notes

  • The extension only changes the literal under the active cursor or cursors.
  • Unsupported output formats are not offered for languages that do not support them.
  • The conversion logic is covered by unit tests and VS Code extension-host integration tests.

Development

npm install
npm test