Jump to content
IGNORED

Decimal to Hex Conversion Tooling?


First Spear

Recommended Posts

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 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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 by carlsson
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

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.)

  • Like 2
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...