I would like to calculate the length of a string in binary number. Is there a function for it, like LEN(STRING_NAME) but return a 2 byte binary?
Thanks!
Do a FMT('00':OCONV(LEN(string_var),'MB'),'R#2')
Thank you Warren for your quick response! Unfortunately, what I want is to convert a number to its native binary number and not the ASCII of the binary number. Your solution will produce:
1=01
2=10
3=11
160=1010000 etc.. in ASCII bytes
whereas I would like to convert
160=รก
168=
211=+ which is the actual binary (now interpreted as ASCII for screen display).
I hope I am clear. Thank you!
You can just use the char() and seq() functions.
I did try CHAR() function but it produces only with a single byte.
SEQ() does what you require, so consult your manual, eg.
PRINT SEQ(168)
displays
Eric
Digit1=INT(LEN(String)/256)
Digit2=MOD(LEN(String),256)
Binary=char(Digit1):char(Digit2)
or
Binary=char(Digit2):char(Digit1)
depending on what order you wish your binary to be in.
Digit1=INT(LEN(String)/256)
Digit2=MOD(LEN(String),256)
Binary=char(Digit1):char(Digit2)
or
Binary=char(Digit2):char(Digit1)
Yes, I think this will do it - thank you all for your help!
David
Try this:
zero_mask=str('0',16)
no_bytes=len(x)
word=fmt1),'R#16')
hi_byte=char(iconv(word1,8,'MB'))
lo_byte=char(iconv(word9,8,'MB'))
word=hi_byte:lo_byte
the largest number that can be represented this way is 65535 (64K). Any number larger than 64K will get truncated (but in this example 'x' cannot be larger than 64K anyway).
It's easier to use hexadecimal:
zero_mask=str('0',4)
no_bytes=len(x)
word=fmt2),'R#4')
hi_byte=char(iconv(word1,2,'MX'))
lo_byte=char(iconv(word3,2,'MX'))
word=hi_byte:lo_byte
Then you can avoid all my previous nonsense by using v118 and V119:
hex_mask=char(0):char(0)
no_bytes=len(x)
call v119(no_bytes,hex_out) ; * converts decimal number to hex char
word=fmt(hex_mask:hex_out,'R#2')
To convert hex characters (binary) to decimal:
call v118(word,dec_out)
Whoops! What am I thinking? This function of V119 is from Revelation, not ARev. V119 in ARev is the sort function. Think they got rid of the old V119 and never replaced it; Aaron, Andrew, what say you?
V119 is alive and well in OpenInsight, sorting happily all you wish to throw at it. Same parameters as it's always been.
The V119 in Revelation had a totally different function than the V119 in ARev. Was this renamed something else in ARev or simply deleted? The Rev V119 did a decimal to hex conversion, output was in a 'binary' format.