Programming Calculator

Hex, binary, byte manipulation, and JS syntax support.

Instacalc supports most JS syntax for hex and byte manipulation:

A few notes:

  • While most JS syntax is allowed (if/else, ? :, "some string"), including user-defined functions and arrow functions, loops (for, while) are currently not supported.
  • Data units (GB, MB) are base 2 (help text explains this). Use MB_SI for base 10.
  • Functions can be called in several ways:
    • 123 as bin
    • 123 -> bin
    • bin(123)

Custom Functions

You can define your own functions using several syntaxes:

// C-style function
function add(a, b) { a + b }
add(10, 20) // 30

// Math-style shorthand
f(x) = x^2 + 10
f(5) // 35

// Arrow functions
square = x => x^2
square(10) // 100
<div class="not-prose"><MiniCalc code={"\n## Array Methods\n\nInstacalc supports functional methods for processing arrays:\n"} /></div>javascript
// Map: transform an array
[1, 2, 3].map(x => x * 10) // [10, 20, 30]

// Filter: keep matching items
[1, 2, 3, 4, 5].filter(x => x > 2) // [3, 4, 5]

// Reduce: combine items into one value
[1, 2, 3, 4].reduce((acc, x) => acc + x) // 10

// Find: locate the first match
[1, 2, 3, 4].find(x => x > 2) // 3

// Sort: sort an array (ascending)
[4, 1, 3, 2].sort() // [1, 2, 3, 4]

// Utility Methods
[1, 2, 3].reverse() // [3, 2, 1]
[1, 2, 3].length    // 3
[1, 2, 3].sum       // 6
[1, 2, 3].avg       // 2
[1, 2, 3].max       // 3
[1, 2, 3].count     // 3
<div class="not-prose"><MiniCalc code={"\n## Pipeline Examples\n\nThe pipeline operator (`->`) is the recommended way to chain multiple array operations for readability:\n"} /></div>javascript
// Example: Square only the odd numbers in a list
[1, 2, 3, 4, 5, 6] 
  -> filter(x => x % 2 != 0) 
  -> map(x => x^2)
// Output: [1, 9, 25]

// Example: Sum of squares for numbers > 10
[5, 12, 8, 15]
  -> filter(x => x > 10)
  -> map(x => x^2)
  -> sum
// Output: 369 (144 + 225)

Note: sort() does not currently support custom comparison functions. Most statistical functions (sum, avg, median, stdev, etc.) can be called as methods on arrays.

  • Binary operators (AND, XOR, NOT) are usually invoked with that keyword. The operators &, | and ^ work with binary/hex arguments: 0x123 ^ 0x456 is XOR, not an exponent (root issue: disambiguating the carat symbol ^).

Example

Explaining big-endian/little-endian and byte swapping: