Table of Contents

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 13:42 by James Sentman
CC Attribution-No Derivative Works 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0