First Spear Posted December 19, 2015 Share Posted December 19, 2015 Hey all. I have a long string of numbers in a text file. I am looking for a program or technique to convert all of the values to hex equivalents in Windows, changing them in the text file. Before I go off in the weeds and code something, I thought I would ask what the gurus are using. The values are used in IntyBASIC. It's kind of academic since Decimal values work, but it is inconsistent where the rest of my programs use Hex. Thanks. 604 , 570 , 570 , 570 , 570 , 570 , 538 , 538 , 508 , 339 , 339 , 339 , 339 , 320 , 339 , 339 , 339 , 320 , 320 , 320 , 452 , 508 , 538 , 570 , 320 , 359 , 538 , 427 , 452 , 427 , 427 , 403 , 403 , 403 , 718 , 718 , 761 , 761 , 339 , 678 , 678 , 761 , 427 , 452 , 508 , 640 , 640 , 761 , 761 , 761 , 678 , 678 , 678 , 678 , 678 , 604 , 604 , 604 , 854 , 854 , 905 , 905 , 678 , 905 , 854 , 761 , 854 , 807 , 718 , 678 , 678 , 678 , 678 , 678 , 678 , 678 , 718 , 718 , 718 , 761 , 761 , 807 , 807 , 807 , 807 , 807 , 807 , 807 , 807 , 807 , 718 , 678 , 678 , 678 , 678 , 678 , 640 , 640 , 640 , 640 , 640 , 640 , 640 , 640 , 320 , 320 , 320 , 427 , 427 , 427 , 403 , 403 , 380 , 302 , 302 , 285 , 285 , 285 , 285 , 285 Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted December 19, 2015 Share Posted December 19, 2015 Here ya go :- $025C, $023A, $023A, $023A, $023A, $023A, $021A, $021A, $01FC, $0153, $0153, $0153, $0153, $0140, $0153, $0153, $0153, $0140, $0140, $0140, $01C4, $01FC, $021A, $023A, $0140, $0167, $021A, $01AB, $01C4, $01AB, $01AB, $0193, $0193, $0193, $02CE, $02CE, $02F9, $02F9, $0153, $02A6, $02A6, $02F9, $01AB, $01C4, $01FC, $0280, $0280, $02F9, $02F9, $02F9, $02A6, $02A6, $02A6, $02A6, $02A6, $025C, $025C, $025C, $0356, $0356, $0389, $0389, $02A6, $0389, $0356, $02F9, $0356, $0327, $02CE, $02A6, $02A6, $02A6, $02A6, $02A6, $02A6, $02A6, $02CE, $02CE, $02CE, $02F9, $02F9, $0327, $0327, $0327, $0327, $0327, $0327, $0327, $0327, $0327, $02CE, $02A6, $02A6, $02A6, $02A6, $02A6, $0280, $0280, $0280, $0280, $0280, $0280, $0280, $0280, $0140, $0140, $0140, $01AB, $01AB, $01AB, $0193, $0193, $017C, $012E, $012E, $011D, $011D, $011D, $011D, $011D Not checked! Quote Link to comment Share on other sites More sharing options...
First Spear Posted December 20, 2015 Author Share Posted December 20, 2015 Thanks playa, but I need to do this a lot, so I am looking for a (command line) tool that will do it. Here ya go :- $025C, $023A, $023A, $023A, $023A, $023A, $021A, $021A, $01FC, $0153, $0153, $0153, $0153, $0140, $0153, $0153, $0153, $0140, $0140, $0140, $01C4, $01FC, $021A, $023A, $0140, $0167, $021A, $01AB, $01C4, $01AB, $01AB, $0193, $0193, $0193, $02CE, $02CE, $02F9, $02F9, $0153, $02A6, $02A6, $02F9, $01AB, $01C4, $01FC, $0280, $0280, $02F9, $02F9, $02F9, $02A6, $02A6, $02A6, $02A6, $02A6, $025C, $025C, $025C, $0356, $0356, $0389, $0389, $02A6, $0389, $0356, $02F9, $0356, $0327, $02CE, $02A6, $02A6, $02A6, $02A6, $02A6, $02A6, $02A6, $02CE, $02CE, $02CE, $02F9, $02F9, $0327, $0327, $0327, $0327, $0327, $0327, $0327, $0327, $0327, $02CE, $02A6, $02A6, $02A6, $02A6, $02A6, $0280, $0280, $0280, $0280, $0280, $0280, $0280, $0280, $0140, $0140, $0140, $01AB, $01AB, $01AB, $0193, $0193, $017C, $012E, $012E, $011D, $011D, $011D, $011D, $011D Not checked! Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted December 20, 2015 Share Posted December 20, 2015 Thanks playa, but I need to do this a lot, so I am looking for a (command line) tool that will do it. For only this set of data or for several sets of data? Is it possible to modify the tool this data comes from to output hex instead? Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted December 20, 2015 Share Posted December 20, 2015 Online tool: http://www.asciitohex.com/ Scroll down to the decimal window and hit convert. Your set will appear in all the other windows. Tho you'll need to replace the commas again (easy enough to search&replace the spaces in a text editor). 1 Quote Link to comment Share on other sites More sharing options...
+DZ-Jay Posted December 21, 2015 Share Posted December 21, 2015 Hey all. I have a long string of numbers in a text file. I am looking for a program or technique to convert all of the values to hex equivalents in Windows, changing them in the text file. Before I go off in the weeds and code something, I thought I would ask what the gurus are using. The values are used in IntyBASIC. It's kind of academic since Decimal values work, but it is inconsistent where the rest of my programs use Hex. Thanks. 604 , 570 , 570 , 570 , 570 , 570 , 538 , 538 , 508 , 339 , 339 , 339 , 339 , 320 , 339 , 339 , 339 , 320 , 320 , 320 , 452 , 508 , 538 , 570 , 320 , 359 , 538 , 427 , 452 , 427 , 427 , 403 , 403 , 403 , 718 , 718 , 761 , 761 , 339 , 678 , 678 , 761 , 427 , 452 , 508 , 640 , 640 , 761 , 761 , 761 , 678 , 678 , 678 , 678 , 678 , 604 , 604 , 604 , 854 , 854 , 905 , 905 , 678 , 905 , 854 , 761 , 854 , 807 , 718 , 678 , 678 , 678 , 678 , 678 , 678 , 678 , 718 , 718 , 718 , 761 , 761 , 807 , 807 , 807 , 807 , 807 , 807 , 807 , 807 , 807 , 718 , 678 , 678 , 678 , 678 , 678 , 640 , 640 , 640 , 640 , 640 , 640 , 640 , 640 , 320 , 320 , 320 , 427 , 427 , 427 , 403 , 403 , 380 , 302 , 302 , 285 , 285 , 285 , 285 , 285 I typically employ custom Perl scripts to do this sort of work for me. If you have Perl installed, I can whip up something quick for you. -dZ. Quote Link to comment Share on other sites More sharing options...
First Spear Posted December 21, 2015 Author Share Posted December 21, 2015 Thanks for the offer. Just to get by, I am going to use the website from Nukey. I will end up making another QnD console app in C# since the conversion will have to be part of a muti-step process, I discovered last night. Quote Link to comment Share on other sites More sharing options...
carlsson Posted December 21, 2015 Share Posted December 21, 2015 (edited) If you have access to sed, awk and od (i.e. Linux, *BSD but also present in Msys for Windows or other type of coreutils or binutils), you can get rather far with this little script. The bug lies in that you get a leading comma on each row and that od only groups eight hexadecimal numbers per row (unless you add the -w parameter to get more bytes per row), so you might want to concatenate rows afterwards. #!/bin/sh sed -e 's/,/\n/g' $1 | awk '{ high = int($1/256); low=$1-(high*256); printf "%c%c",low,high }' | od -An -x | sed -e 's/ / ,\$/g' exit 0 Edited December 21, 2015 by carlsson Quote Link to comment Share on other sites More sharing options...
intvnut Posted December 23, 2015 Share Posted December 23, 2015 I usually just use bc and vi under Linux, myself, if it were just a one-off. Or, like dZ says upthread, whip up a Perl script to do it if I have many to do. All of these are available under Windows, but aren't really Windows-native solutions. With Perl, something short like this might work, if your input consisted solely of lines with decimal numbers separated by commas and whitespace: . while (<>) { my @data = split /\s*,\s*/; if (!@data) { print $_; next; } my @hex = map { sprintf '$%04X', $_ } @data; print( join( ',', @hex ) ); } . Sure, we could code-golf that into less code, but you get the idea. 1 Quote Link to comment Share on other sites More sharing options...
Arnauld Posted January 8, 2016 Share Posted January 8, 2016 You can also do that in a browser console, using either FireBug or the built-in debugging tools which are usually accessible by pressing F12. [ 604, 570, 570, 570, 570, 570, 538, 538, 508, 339 ].map(function(n) { return '$' + n.toString(16); }).join(', ') (list shortened for readability) In recent versions of Firefox, the content of an alert box can be selected and copied to the clipboard (that may be true for other browsers but I don't know for sure). Therefore, you can also put that directly in the address bar of a non-blank page: javascript:alert([ 604, 570, 570, 570, 570, 570, 538, 538, 508, 339 ].map(function(n) { return '$' + n.toString(16); }).join(', ')) (You may have to add 'javascript:' manually. It gets automagically truncated after a copy/paste of the whole string, at least in my version of Firefox.) 2 Quote Link to comment Share on other sites More sharing options...
Arnauld Posted January 8, 2016 Share Posted January 8, 2016 And by the way: can someone please explain me how to add spacing before/after code snippets in AtariAge? I just can't figure it out. ^^ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.