RE: Binary conversion
- Posted by Jonas Temple <jktemple at yhti.net> Aug 16, 2002
- 453 views
What a great community this is! I really appreciate everyone's willingness to help. Here's a little more background to my problem and the solution I came up with. I have an atom with a value of 90. If you were to poke4() this atom to memory and then peek4() you would get {90,0,0,0}. Since the iSeries expects the reverse order I called a translation routine to reverse the order before passing to the iSeries. Everything worked up to that point. When the data was returned to my PC is was {0,0,0,91} (remembering that I reversed it and the program on the iSeries added 1 to the number). I liked the reverse() and bytes_to_int() solution and it worked, but not on negative values (the doc states that bytes_to_int expects the sequence to contain positive values). I thought about Derek's multiplication approach but here's what I came up with: atom bin, parm sequence rtn_seq ...some stuff in here... bin = allocate(4) rtn_seq = reverse(rtn_seq) poke(bin, rtn_seq) parm = peek4s(bin) free(bin) So what I accomplished was I used reverse() to put the sequence back into the order needed for an atom, poked the sequence to memory and then used peek4s to get the value back out. Maybe not the most elegant solution but it worked nonetheless. Thanks again to everyone!