Announcement

Collapse
No announcement yet.

Substring

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Decode
    replied


    Steve

    That's exactly what I needed.

    Thanks a lot

    Leave a comment:


  • smcmanus
    replied
    Not sure if this is what you are after. Your statement:

    (this is what I want)
    s1 = A
    s2 = B
    is ambiguous.

    The code below extracts the target HEX digit and shows how to treat the extracted target as a HEX value or index into a string to extract the character value.

    #platform "uOLED-32028-P1T"
    /*************************************************
    * Filename: Parse_HEX_String.4dg
    * Created: 2009/08/30
    * Author: Steve McManus
    * Description: Extract the HEX digits and character
    * values from a HEX variable
    **************************************************/
    #DATA
    byte hexval
    "0123456789ABCDEF"
    #END

    func main()
    var t, s, s1, s2;
    s := 0xABCD;

    t:=s>>12; //shift s right 12 bits
    t:=t&0x000F; //clear first 12 bits
    s1:=hexval[t]; //index into hexval string
    print([HEX4] t,"\n\n"); //print HEX value of t - 0x000A

    t:=s>>8; //shift s right 8 bits
    t:=t&0x000F; //clear first 12 bits
    s2:=hexval[t]; //index into hexval string
    print([HEX4] t,"\n\n"); //print HEX value of t - 0x000B

    print([CHR]s1, "\n\n"); //print character values of s1 & s2
    print([CHR]s2, "\n");

    repeat forever
    endfunc


    Steve


    Leave a comment:


  • Decode
    started a topic Substring

    Substring

    Hi guys,

    How can I do this:

    var s, s1, s2;

    s := 0xABCD

    (this is what I want)
    s1 = A
    s2 = B

    Thanks!
Working...
X