int2: convert integers, string to integer vector

Description Usage Arguments Details Value Author(s) Examples

Description

Functions for conversion to string representation of integers to arbitrary bases

Usage

1
2
3
4
5
6
  NdM( x, B=10 )
  int2ASCII( n)
  int2B( n, B=10, space, plus=lead, lead="",just=c("left","right","center","none") )
  int2Oct( n )
  int2Hex( n )
  strRound( str, digits = getOption("digits"), B=10)

Arguments

str

String representing a real

n

Integer vector

B

1 < integer < 17, base of representation

space

Integer, space for conversion

plus

string for signifying positive values, usually "" or "+"

lead

string for insertion between sign and first significant digit, usually "" or "0"

just

String for choosing kind of justification within 'space', partial matching allowed

x

Vector of reals

digits

no. of digits for roeunding

Details

int2Oct Convert integer to octal representation.
int2Hex Convert integer to hex representation

Value

NdM maximum number of decimal places needed for trunc(x)
int2ASCII,int2B,int2Oct,int2Hex vector of strings represented by 'n'
strRound real, represented by x

Author(s)

Christian W. Hoffmann <christian@echoffmann.ch>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  NdM(10^(1:4)) # 5
  int2ASCII(1:255)[121:129] # "x" "y" "z" "{" "|" "}" "~" "\177" "\200"
  int2B(1:50,2) # all of same length
  int2B(1:50*(-1)^(1:50),just="r") # left flush
  unlist(sapply(1:50,int2B,2,just="l")[1,] ) # individual lengths
  unlist(sapply(1:50,int2B,7)[1,] ) # individual lengths
  unlist(sapply(1:50,int2B)[1,] )
  unlist(sapply(1:50,int2Oct)[1,] )
  unlist(sapply(1:50,int2Hex)[1,] )
  strRound(pi*10^4,0)/10^4 == strRound(pi,4) # TRUE

Example output

Loading required package: lattice
Loading required package: grid
[1] 4
[1] "x"    "y"    "z"    "{"    "|"    "}"    "~"    "\177" "\x80"
There were 50 or more warnings (use warnings() to see the first 50)
[[1]]
 [1] "     1" "    10" "    11" "   100" "   101" "   110" "   111" "  1000"
 [9] "  1001" "  1010" "  1011" "  1100" "  1101" "  1110" "  1111" " 10000"
[17] " 10001" " 10010" " 10011" " 10100" " 10101" " 10110" " 10111" " 11000"
[25] " 11001" " 11010" " 11011" " 11100" " 11101" " 11110" " 11111" "100000"
[33] "100001" "100010" "100011" "100100" "100101" "100110" "100111" "101000"
[41] "101001" "101010" "101011" "101100" "101101" "101110" "101111" "110000"
[49] "110001" "110010"

[[2]]
[1] 2

[[1]]
 [1] "-1 " "-2 " "-3 " "-4 " "-5 " "-6 " "-7 " "-8 " "-9 " "-10" "-11" "-12"
[13] "-13" "-14" "-15" "-16" "-17" "-18" "-19" "-20" "-21" "-22" "-23" "-24"
[25] "-25" "-26" "-27" "-28" "-29" "-30" "-31" "-32" "-33" "-34" "-35" "-36"
[37] "-37" "-38" "-39" "-40" "-41" "-42" "-43" "-44" "-45" "-46" "-47" "-48"
[49] "-49" "-50"

[[2]]
[1] 10

 [1] "1"      "10"     "11"     "100"    "101"    "110"    "111"    "1000"  
 [9] "1001"   "1010"   "1011"   "1100"   "1101"   "1110"   "1111"   "10000" 
[17] "10001"  "10010"  "10011"  "10100"  "10101"  "10110"  "10111"  "11000" 
[25] "11001"  "11010"  "11011"  "11100"  "11101"  "11110"  "11111"  "100000"
[33] "100001" "100010" "100011" "100100" "100101" "100110" "100111" "101000"
[41] "101001" "101010" "101011" "101100" "101101" "101110" "101111" "110000"
[49] "110001" "110010"
 [1] "1"   "2"   "3"   "4"   "5"   "6"   "10"  "11"  "12"  "13"  "14"  "15" 
[13] "16"  "20"  "21"  "22"  "23"  "24"  "25"  "26"  "30"  "31"  "32"  "33" 
[25] "34"  "35"  "36"  "40"  "41"  "42"  "43"  "44"  "45"  "46"  "50"  "51" 
[37] "52"  "53"  "54"  "55"  "56"  "60"  "61"  "62"  "63"  "64"  "65"  "66" 
[49] "100" "101"
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14" "15"
[16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
[31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45"
[46] "46" "47" "48" "49" "50"
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "10" "11" "12" "13" "14" "15" "16" "17"
[16] "20" "21" "22" "23" "24" "25" "26" "27" "30" "31" "32" "33" "34" "35" "36"
[31] "37" "40" "41" "42" "43" "44" "45" "46" "47" "50" "51" "52" "53" "54" "55"
[46] "56" "57" "60" "61" "62"
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "A"  "B"  "C"  "D"  "E"  "F" 
[16] "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B" "1C" "1D" "1E"
[31] "1F" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "2A" "2B" "2C" "2D"
[46] "2E" "2F" "30" "31" "32"
[1] TRUE

cwhmisc documentation built on May 1, 2019, 7:55 p.m.