Shop OBEX P1 Docs P2 Docs Learn Events
Wanted: A dec conversion that returns a single value — Parallax Forums

Wanted: A dec conversion that returns a single value

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2012-07-02 14:39 in Propeller 1
I'm hunting for something that I suspect exists, but I can't seem to lay my hands on it..

I need a DEC conversion routine that converts to a single byte value. Most of the common conversion routines like those that are included in video and serial drivers seem to simply place bytes on the screen. What I'm looking for is one that will convert to a single value.

Have I missed something obvious here?

Thanks
OBC

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-07-02 11:40
    I'm confused. Is what you're after something to convert a string of 1-3 ASCII digits to a byte value? If so, there should be something in SimpleNumbers to do that.

    -Phil
  • turbosupraturbosupra Posts: 1,088
    edited 2012-07-02 13:15
    Is this what you are looking for? I can't seem to get much else right today so hopefully I did this correctly.

    Apparently the limit for case statement is 64, so if you don't need all 128 standard ascii charcters, maybe you can disable the ones you don't need to stay within that 64 case limit or just use the if statements I have


    pub decToAscii(decimal)
    
      if (decimal =< 63)
         
        case decimal
          0:
            result := string("NUL")
         
          1:
            result := string("SOH")
            
          2:
            result := string("STX")
            
          3:
            result := string("ETX")
            
          4:
            result := string("EOT")
            
          5:
            result := string("ENQ")
            
          6:
            result := string("ACK")
            
          7:
            result := string("BEL")
            
          8:
            result := string("BS")
            
          9:
            result := string("HT")
            
          10:
            result := string("LF")
            
          11:
            result := string("VT")
            
          12:
            result := string("FF")
            
          13:
            result := string("CR")
            
          14:
            result := string("SO")
            
          15:
            result := string("SI")
            
          16:
            result := string("DLE")
            
          17:
            result := string("DC1")
            
          18:
            result := string("DC2")
            
          19:
            result := string("DC3")
            
          20:
            result := string("DC4")
            
          21:
            result := string("NAK")
            
          22:
            result := string("SYN")
            
          23:
            result := string("ETB")
            
          24:
            result := string("CAN")
            
          25:
            result := string("EM")
            
          26:
            result := string("SUB")
            
          27:
            result := string("ESC")
            
          28:
            result := string("FS")
            
          29:
            result := string("GS")
            
          30:
            result := string("RS")
            
          31:
            result := string("US")
            
          32:
            result := string("SP")
            
          33:
            result := string("!")
            
          34:
            result := string("''")
            
          35:
            result := string("#")
            
          36:
            result := string("$")
            
          37:
            result := string("%")
            
          38:
            result := string("&")
            
          39:
            result := string("'")
            
          40:
            result := string("(")
            
          41:
            result := string(")")
            
          42:
            result := string("*")
            
          43:
            result := string("+")
            
          44:
            result := string(",")
            
          45:
            result := string("-")
            
          46:
            result := string(".")
            
          47:
            result := string("/")
            
          48:
            result := string("0")
            
          49:
            result := string("1")
            
          50:
            result := string("2")
            
          51:
            result := string("3")
            
          52:
            result := string("4")
            
          53:
            result := string("5")
            
          54:
            result := string("6")
            
          55:
            result := string("7")
            
          56:
            result := string("8")
            
          57:                 
            result := string("9")
            
          58:
            result := string(":")
            
          59:
            result := string(";")
            
          60:
            result := string("<")
            
          61:
            result := string("=")
            
          62:
            result := string(">")
            
          63:
            result := string("?")
    
      elseif (decimal > 63)
      
        case decimal   
          64:
            result := string("@")
            
          65:
            result := string("A")
            
          66:
            result := string("B")
            
          67:
            result := string("C")
            
          68:
            result := string("D")
            
          69:
            result := string("E")
            
          70:
            result := string("F")
            
          71:
            result := string("G")
            
          72:
            result := string("H")
            
          73:
            result := string("I")
            
          74:
            result := string("J")
            
          75:
            result := string("K")
            
          76:
            result := string("L")
            
          77:
            result := string("M")
            
          78:
            result := string("N")
            
          79:
            result := string("O")
            
          80:
            result := string("P")
            
          81:
            result := string("Q")
            
          82:
            result := string("R")
            
          83:
            result := string("S")
            
          84:
            result := string("T")
            
          85:
            result := string("U")
            
          86:
            result := string("V")
            
          87:
            result := string("W")
            
          88:
            result := string("X")
            
          89:
            result := string("Y")
            
          90:
            result := string("Z")
            
          91:
            result := string("[")
            
          92:
            result := string("\")
            
          93:
            result := string("]")
            
          94:
            result := string("^")
            
          95:
            result := string("_")
            
          96:
            result := string("`")
            
          97:
            result := string("a")
            
          98:
            result := string("b")
            
          99:
            result := string("c")
            
          100:
            result := string("d")
            
          101:
            result := string("e")
            
          102:
            result := string("f")
            
          103:
            result := string("g")
            
          104:
            result := string("h")
            
          105:
            result := string("i")
            
          106:
            result := string("j")
            
          107:
            result := string("k")
            
          108:
            result := string("l")
            
          109:
            result := string("m")
            
          110:
            result := string("n")
            
          111:
            result := string("o")
            
          112:
            result := string("p")
            
          113:
            result := string("q")
            
          114:
            result := string("r")
            
          115:
            result := string("s")
            
          116:
            result := string("t")
            
          117:
            result := string("u")
            
          118:
            result := string("v")
            
          119:
            result := string("w")
            
          120:
            result := string("x")
            
          121:
            result := string("y")
            
          122:
            result := string("z")
            
          123:
            result := string("{")
            
          124:
            result := string("|")
            
          125:
            result := string("}")
            
          126:
            result := string("~")
            
          127:
            result := string("DEL")
       
    
  • lonesocklonesock Posts: 917
    edited 2012-07-02 14:09
    A single decimal digit out, something like this?

    c := "0" + v

    where v is in the range [0..9]. If you want to NULL-terminate the "string", make c an array of 2 bytes, where the 2nd one is 0.

    Jonathan
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2012-07-02 14:39
    @lonesock. That's what I was fishing for! Thank you!

    OBC
Sign In or Register to comment.