A char2num function that works for ASCII codes 0-->255.

The inbuilt char2num function only works properly for ASCII codeset characters lying in between 0 and 127. However a lot of internet based applications, such as telnet, use characters above 127 regularly. These don't print properly in IGOR. This snippet performs the char2num function for characters that lie in between 0 and 255.
i.e. one gets around the problem:
print char2num(num2char(56))
56
print char2num(num2char(249))
-7
print num2char(249)
ÿ



Function extendedASCIIchar2num(chars)
    string chars
    make/o/t/n=(strlen(chars),2) W_chartranslation
    variable ii,decChar
    for(ii=0 ; ii < strlen(chars) ; ii+=1)
        W_chartranslation[ii][0] = chars[ii]

        decChar = char2num(chars[ii])
        if( 0 <= decChar && decChar <= 127)
            W_chartranslation[ii][1] = num2istr(decChar)
        else
            W_chartranslation[ii][1]= num2istr(255 + decChar + 1)  
        endif
    endfor
End

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More