Guys,
It is very simple to enter a hex constant in J :
16bbed
Is there a recommended way to "unhex" such a constant?
e.g.
]hexdata =: 16babc NB Establish hex data
2748
.
.
alpha=:'0123456789abcdef' NB Hex alphabet
.
.
NB. I want to retrieve the hex data "abc"
NB. let's try Antibase #: although I need to know the
NB. output length which is clumsy
alpha {~ 16 16 16 #: hexdata
abc
NB. That looks OK! Let's try another
alpha {~ 16 16 16 #: 16bfff +16bcac
cab
NB. Whoops! Used an extra digit
alpha {~ 16 16 16 16 #: 16bfff +16bcac NB. So this works!
1cab
alpha {~ (4#16) #: 16bfff +16bcac NB. This also works!
1cab
alpha {~ (16 # 16) #: 16b0123456789abcdef NB. This doesn't
|domain error
| alpha {~(16#16)#:8.19855e16
NB. What I really want is:
NB. hexdata=: 16babcde
NB. 4 unhex hexdata NB. unhex into a 4-byte field
NB. 000abcde
NB. _ unhex hexdata NB. use as many bytes as necessary
NB. 0abcde
NB. _ unhex 16b0123456789abcdef
NB. 0123456789abcdef
NB. _ unhex 16bfff + 16bcac
NB. 1cab
NB. 1 unhex 16bfff + 16bcac
NB. Overflow error
Thanks in advance for a neat way to do this!
_________________________________________________________________
Use Hotmail to send and receive mail from your different email accounts
http://clk.atdmt.com/UKM/go/186394592/direct/01/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm