Announcement

Collapse
No announcement yet.

Substring

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

  • Substring

    Hi guys,

    How can I do this:

    var s, s1, s2;

    s := 0xABCD

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

    Thanks!

  • #2
    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


    Any technology, sufficiently developed, is indistinguishable from magic. A.C. Clark(RIP)

    NEW! Lower prices on all 4D Systems products for 2009 and continuing into 2010!
    http://shop.littlepcbsolutions.com

    Comment


    • #3


      Steve

      That's exactly what I needed.

      Thanks a lot

      Comment

      Working...
      X