Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 25th, 2007, 1:26 PM   #1
vinit11
Newbie
 
Join Date: Dec 2006
Posts: 18
Rep Power: 0 vinit11 is on a distinguished road
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
vinit11 is offline   Reply With Quote
Old Mar 25th, 2007, 2:00 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Mar 25th, 2007, 2:00 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 25th, 2007, 2:18 PM   #4
vinit11
Newbie
 
Join Date: Dec 2006
Posts: 18
Rep Power: 0 vinit11 is on a distinguished road
* 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 is offline   Reply With Quote
Old Mar 25th, 2007, 2:31 PM   #5
vinit11
Newbie
 
Join Date: Dec 2006
Posts: 18
Rep Power: 0 vinit11 is on a distinguished road
* 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
vinit11 is offline   Reply With Quote
Old Mar 25th, 2007, 2:33 PM   #6
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
I think VC++ 2005 is free, from the MS website
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Mar 25th, 2007, 2:39 PM   #7
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
\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 is offline   Reply With Quote
Old Mar 25th, 2007, 2:39 PM   #8
vinit11
Newbie
 
Join Date: Dec 2006
Posts: 18
Rep Power: 0 vinit11 is on a distinguished road
* 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 is offline   Reply With Quote
Old Mar 25th, 2007, 2:43 PM   #9
vinit11
Newbie
 
Join Date: Dec 2006
Posts: 18
Rep Power: 0 vinit11 is on a distinguished road
Quote:
Originally Posted by titaniumdecoy View Post
\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 is offline   Reply With Quote
Old Mar 25th, 2007, 2:51 PM   #10
vinit11
Newbie
 
Join Date: Dec 2006
Posts: 18
Rep Power: 0 vinit11 is on a distinguished road
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
vinit11 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:49 AM.

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