Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Software Design and Algorithms (http://www.programmingforums.org/forum64.html)
-   -   Adding a 0x Prefix to Hex Values? (http://www.programmingforums.org/showthread.php?t=12870)

vinit11 Mar 25th, 2007 2:26 PM

Adding a 0x Prefix to Hex Values?
 
Hey Folks,

First, off I apologise if this is not the right forum to post this question. I wasn't sure what the "best fit" would be.

I’ve a table with 3200 hex entries in a spreadsheet but they’re all missing the “0x” prefix. I’d like to add that in front of each entry. Do you know how to?

In other words consider the following 2 x 3 table:

[HTML]02 00 FF
EE FA DA[/HTML]

I’d like to make it look like this:

[HTML]0x02 0x00 0xFF
0xEE 0xFA 0xDA[/HTML]

There should be some text editor which does that – right? I’ve been trying to look for one but with no luck so far.

Thanks for your time,

Vinit

DaWei Mar 25th, 2007 3:00 PM

Almost any editor one thinks of that supports regular expressions will do the trick. That would be many. The editor in VC++ 2005, for instance, is among them.

Ooble Mar 25th, 2007 3:00 PM

Find any text editor that can use regular expressions (I'd recommend Notepad++ for Windows, TextWrangler for Mac OS or Kate for Linux), and tell it to replace ([0-9A-Fa-f]{2}) with 0x\1. This should do it.

For more information on regular expressions, check out Regular-Expressions.info.

vinit11 Mar 25th, 2007 3:18 PM

* DaWei,

Thank you for the reply. I don't have VC++ 2005. I was hoping there would be something free or bundled with Windows that could do the trick.

* Ooble,

Thanks for your contribution. I'll try to get Notepad++. I'm not sure I understand what you wrote:

[HTML]([0-9A-Fa-f]{2}) with 0x\1[/HTML]

but it seems to be some kind of a command line argument. I'll check out the link you sent too and see if it makes sense.

Thanks much,

Vinit

vinit11 Mar 25th, 2007 3:31 PM

* Ooble,

Now, I understand what you wrote. Essentially, you're saying find any hex number that is two digits long that may be of a mixed case and prefix it with it a "0x". I'm not sure what the "\1" means, yet but I'm trying to understand that.

I have Notepad++ installed and I'm trying to figure out how or where exactly to type in your command.

Vinit

kruptof Mar 25th, 2007 3:33 PM

I think VC++ 2005 is free, from the MS website

titaniumdecoy Mar 25th, 2007 3:39 PM

\1 is replaced by the matched text. So if the pattern matched by [0-9A-Fa-f]{2} was FA, 0x\1 would become 0xFA.

vinit11 Mar 25th, 2007 3:39 PM

* kruptof,

Thank you.

Yes, it is indeed free. However, one has to uninstall the 2.0 Net framework before installing it which I can't do. :-(

Vinit

vinit11 Mar 25th, 2007 3:43 PM

Quote:

Originally Posted by titaniumdecoy (Post 125713)
\1 is replaced by the matched text. So if the pattern matched by [0-9A-Fa-f]{2} was FA, 0x\1 would become 0xFA.

* titaniumdecoy,

Thanks for your input.

Hmm - I still don't get what the "\1" does, really. I understand what you're saying with regards to "FA" becoming "0xFA" but what if I had "0x\2", instead, for example? What would "FA" become then?

Vinit

vinit11 Mar 25th, 2007 3:51 PM

OK, so now that I'm getting clearer with this, I fired up Notepad++, opened my text file, and then went to:

Search --> Replace...

In the "Find what" field, I typed in:

([0-9A-Fa-f]{2})

and in the "Replace with" field, I typed in:

0x\1

However, I get a dialog box with the following message which says "Can't find the word". Am I missing something vital?

Vinit


All times are GMT -5. The time now is 2:21 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC