User Tools

Site Tools


Sidebar

dictionary:bitwise:texttonumber

Text To Number

Takes a text representation of a number in various formats and returns an AppleScript integer of the result. Can convert strings containing hex or binary or octal to a number as well as regular numerical strings.

Usage:

text to number (text: representing a number. Use a number specifier below for special number systems)
returns an AppleScript Integer.

NOTE: real numbers containing decimals will be truncated. Use the standard “as number” conversion in AppleScript to convert those.

Number Specifiers

By using these prefixes to the number string this command can work with decimal numbers, binary numbers, hexadecimal numbers even octal numbers.

  • “&h” to denote the following number is hex, like “&hAABBCC22“
  • “&b” to denote the following number is a binary string, like “&b11010011”
  • “&o” to denote the following number is an octal string, like “&o4522“
  • for decimal numbers no prefix is necessary, like “23”

Examples:

  set myValue to (text to number “23”)
  
  set myHexValue to (text to number “&hA4B211”)
  
  set myBinaryValue to (text to number “&b1011010111”)
  
  set myOctalValue to (text to number “&o321274”)
dictionary/bitwise/texttonumber.txt · Last modified: 2017/03/06 18:42 (external edit)