Skip to content

Latest commit

 

History

History
145 lines (74 loc) · 6.4 KB

cip.1.ronn

File metadata and controls

145 lines (74 loc) · 6.4 KB

cip(1) -- convert integer and print

SYNOPSIS

cip [-opts]

cip [-opts] [ number | Unicode_string ] ...

cip [-opts] -r [ min ] max [ step ]

DESCRIPTION

cip accepts numbers or Unicode characters as input, and prints them as base 2, 8, 10, or 16 numbers or as Unicode UTF-8 characters.

When cip is not being used to generate a sequence (with the -r option), the input can be either from the standard input or the command's arguments.

The input is read as whitespace-separated words. The words must be in a format cip understands as numbers. By default, numbers can be integers in decimal (base 10) notation, octal (base 8) numbers with a leading 0 (zero), hexidecimal (base 16) numbers with a leading 0x, or Unicode code points (a prefix of U+ followed by hexidecimal digits). A mix of numeric bases may be present.

Alternatively, the numeric base of the number(s) in the input can be set using the -ib=base option, in which case prefixes are not allowed, and all of the numbers must have the specified numeric base, which can be from 2 to 36.

cip can output numbers only in bases 2, 8, 10, or 16. The -o option specifies base 8 (octal), and numbers are printed with a leading 0 (zero). Hexidecimal output can be specified using any of -x, -X, -h, or -H, and the numbers are printed with a leading 0x prefix. Using -X or -H results in the numbers being printed using capital A-F letters, rather than lowercase.

To avoid printing of prefixes, the output base can be specified using either the -ob=8 or -ob=16 option. Either of -X or -H may be added to -ob=16 to specify that the numbers should be printed with uppercase A-F digits.

When arguments are provided (without the -r flag, which is explained below), cip concatenates the arguments with space characters (Unicode U+0020) as separators and treats the result the same way as it would an input file.

The exception to both of the above is when the -ic flag is provided, the input (either from standard input or concatenated arguments) is a string of characters with no separators between them. Internally, cip converts the Unicode characters into their (integer) code points.

With the -r (range) option, cip generates a range of numbers to print, rather than reading numbers from the input.

OPTIONS

Options may be specified in any way supported by the flags package in the Go standard library.

Output base or method

By default, cip outputs decimal (base 10) integers. To output in other formats or numeric bases, only one of the following may be supplied:

-b Numeric output in binary (base 2).

-o Numeric output in octal (base 8).

-h (or -x) Numeric output in hexidecimal (base 16), using lowercase letters a-f to represent digits 10-15.

-H (or -X) Numeric output in hexidecimal (base 16), using uppercase letters A-F to represent digits 10-15.

-U Output in Unicode standard form for code points: U+DDDD, where the Ds are hexidecimal digits, using uppercase A-F.

-ob _base_ Set the numeric base for output to base. Only values of 2, 8, 10, and 16 are allowed.

-c Unicode character output.

Input Base

By default, cip interprets input numbers as decimal (base 10) integers. To accept input in other bases or as Unicode characters, only one of the following may be supplied:

-ib base Use base as the numeric base of the input. base can be any integer from 2 to 36. The letters A-Z, either uppercase or lowercase, are used to represent digits greater than 9.

-ic Accept Unicode characters as input. The characters are converted to their Unicode code points.

Output Formatting

-n When using -c to output Unicode characters, don't print a newline at the end of the line.

-p string Use string as a prefix to apply to every number in the output.

-s string Use string to separate numbers in the output. string may include \t, \n and other characters recognized by strconv.Unquote() in the Go standard library.

-w Constant-width output. When generating a sequence, pad the shorter numbers with 0s to make all of the numbers equal width.

-width number Pad all numbers in the output with 0s to make them (at least) equal in width to number characters.

Only one of -w and -width may be supplied. The -w option works only with the -r option.

Other options

-r [ min ] max [ step ] Range. Output a sequence of integers or characters starting at min and ending at (or before) max, incrementing or decrementing by step (min can be greater than max, resulting in cip counting downwards by step. By using the -ic option, min and max can both be specified as Unicode characters, but step must always be specified by a positive base 10 integer.

-help Print a help message.

ARGUMENTS

There are two types of non-option arguments. When the -r option is not in use, supplying one or more arguments causes cip to accept input from the argument(s).

When the -r option is specified, the arguments specify the range of a sequence of integers or characters to generate. With one argument, the range is from 1 to the value of the argument. When two arguments are given, the range is from the first to the second argument.

If the second argument is less than the first, cip will count downwards from the first towards the second.

If an additional argument is given, it specifies the amount by which to increment or decrement while stepping through the sequence.

EXAMPLES

Print 237 in binary

cip -b 237

Convert 0xED to decimal

cip 0xed

or

cip -ib=16 ed

or

cip -ib=16 ED

Print a sequence of octal numbers from 90 (base 10) to 177 (base 8)

cip -o -r 90 0177

or

cip -ob=8 -r 90 0177

Print the lowercase Greek alphabet

cip -c -r 0x3b1 0x3c9

CAVEAT UTILITOR

Omitting the < for standard input redirection.

cip -ic -c input

prints "input", not the contents of a file named input.

SEE ALSO

od(1), hd(1), seq(1), numconv(1)

Option Parsing

Integer Parsing

strconv.Unquote()

The Unicode Standard

AUTHOR

Jay Ts (http://jayts.com)