![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2006
Posts: 18
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Dec 2006
Posts: 18
Rep Power: 0
![]() |
* 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 |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Dec 2006
Posts: 18
Rep Power: 0
![]() |
* 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 |
|
|
|
|
|
#6 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3
![]() |
I think VC++ 2005 is free, from the MS website
__________________
Quote:
|
|
|
|
|
|
|
#7 |
|
Expert Programmer
|
\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.
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: Dec 2006
Posts: 18
Rep Power: 0
![]() |
* 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 |
|
|
|
|
|
#9 | |
|
Newbie
Join Date: Dec 2006
Posts: 18
Rep Power: 0
![]() |
Quote:
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 |
|
|
|
|
|
|
#10 |
|
Newbie
Join Date: Dec 2006
Posts: 18
Rep Power: 0
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding div elements with JavaScript | Wizard1988 | JavaScript and Client-Side Browser Scripting | 4 | Feb 25th, 2007 11:05 AM |
| adding of integers | mrynit | C++ | 7 | Jun 2nd, 2006 12:01 AM |
| adding printing deleting values from a min heap | cwl157 | C++ | 15 | Mar 23rd, 2006 11:52 PM |
| Returning two values | Navid | C | 19 | Jun 13th, 2005 2:57 AM |
| Problem Inserting Values into mySQL from PHP | stakeknife | PHP | 1 | Mar 23rd, 2005 8:45 AM |