Base-16 representation

From Rosetta Code
Revision as of 08:14, 2 June 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} ;Task:Numbers in base-16 representation that cannot be written with decimal digits, where '''n < 501''' <br><br> =={{header|Ring}}== <lang ring> load "stdlib...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Base-16 representation is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task
Numbers in base-16 representation that cannot be written with decimal digits, where n < 501



Ring

<lang ring> load "stdlib.ring" see "working..." + nl decList = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] baseList = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"] baseAbcList = ["A","B","C","D","E","F"] row = 1 limit = 200

for n = 1 to limit

   num = 0
   flag = 1
   hex = decimaltobase(n,16)
   lenHex = len(hex)
   for m = 1 to lenHex        
       ind = find(baseAbcList,hex[m])
       if ind < 1
          num = num + 1
       ok
   next
   if num != lenHex
      row = row + 1
      see "" + n + " "
      if row%10 = 0
         see nl
      ok
   ok

next

see nl + "done..." + nl

func decimaltobase(nr,base)

    binList = [] 
    binary = 0
    remainder = 1
    while(nr != 0)
         remainder = nr % base
         ind = find(decList,remainder)
         rem = baseList[ind]
         add(binList,rem)
         nr = floor(nr/base) 
    end
    binlist = reverse(binList)
    binList = list2str(binList)
    binList = substr(binList,nl,"")  
    return binList

</lang>

Output:
working...
10 11 12 13 14 15 26 27 28 
29 30 31 42 43 44 45 46 47 58 
59 60 61 62 63 74 75 76 77 78 
79 90 91 92 93 94 95 106 107 108 
109 110 111 122 123 124 125 126 127 138 
139 140 141 142 143 154 155 156 157 158 
159 160 161 162 163 164 165 166 167 168 
169 170 171 172 173 174 175 176 177 178 
179 180 181 182 183 184 185 186 187 188 
189 190 191 192 193 194 195 196 197 198 
199 200 
done...