Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Newbie hexadecimal question

Reply
Thread Tools

Newbie hexadecimal question

 
 
Jim Lake
Guest
Posts: n/a
 
      11-28-2004
I'm creating a string of hex characters and I have an unsigned char
value of 00 assigned to the name IS.
I try m_strResp += IS to append the hex 00 to the hex characters
already in m_strResp and I get a C2593 compile error (error
C2593: 'operator +=' is ambiguous). I can see where adding 0 to
something is ambiguous but I'm not trying to do arithmetic. I'm
trying to create a string of hex characters.
Any suggestions?
Thanks!
 
Reply With Quote
 
 
 
 
ajk
Guest
Posts: n/a
 
      11-28-2004
On 28 Nov 2004 05:43:44 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) (Jim Lake) wrote:

>I'm creating a string of hex characters and I have an unsigned char
>value of 00 assigned to the name IS.
>I try m_strResp += IS to append the hex 00 to the hex characters
>already in m_strResp and I get a C2593 compile error (error
>C2593: 'operator +=' is ambiguous). I can see where adding 0 to
>something is ambiguous but I'm not trying to do arithmetic. I'm
>trying to create a string of hex characters.
>Any suggestions?
>Thanks!


you could try using stringstream instead:

#include <sstream>
#include <iomanip>

....

stringstream ss;
int somevalue = 0;
ss << hex << somevalue;

cout << ss.str() << endl;

/ajk
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      11-28-2004
* Jim Lake:
> I'm creating a string of hex characters and I have an unsigned char
> value of 00


No, you don't.

> assigned to the name IS.


No, you don't. That is at best a macro definition. Don't use
macros.


> I try m_strResp += IS


Don't use mangled names, use meaningful names.


> to append the hex 00 to the hex characters
> already in m_strResp and I get a C2593 compile error (error
> C2593: 'operator +=' is ambiguous).


The following code reproduces your problem:

#include <string>

int main()
{
std::string s;

s += 0;
}

Always post code that reproduces the problem. Copy and paste
the code. Don't type it in.


> I can see where adding 0 to
> something is ambiguous but I'm not trying to do arithmetic. I'm
> trying to create a string of hex characters.
> Any suggestions?


As already stated: don't use macros. A macro does not have a type.
And that's the direct cause of your problem.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
Jim Lake
Guest
Posts: n/a
 
      11-28-2004
#include <string>

int main()
{
std::string s;

s += 0;
}

c:\documents and settings\administrator.the_domain\my documents\my
projects\test.cpp(6) : error C2593: 'operator +=' is ambiguous

c:\documents and settings\administrator.the_domain\my documents\my
projects\test.cpp(7) : warning C4508: 'main' : function should return
a value; 'void' return type assumed

How is this adding a hex 00 to a string (group) of hex characters?

I'm looking to add a hex 00 to this: FF FA

I want this-->FF FA to become this--> FF FA 00

(E-Mail Removed) (Alf P. Steinbach) wrote in message news:<(E-Mail Removed)>...
> * Jim Lake:
> > I'm creating a string of hex characters and I have an unsigned char
> > value of 00

>
> No, you don't.
>
> > assigned to the name IS.

>
> No, you don't. That is at best a macro definition. Don't use
> macros.
>
>
> > I try m_strResp += IS

>
> Don't use mangled names, use meaningful names.
>
>
> > to append the hex 00 to the hex characters
> > already in m_strResp and I get a C2593 compile error (error
> > C2593: 'operator +=' is ambiguous).

>
> The following code reproduces your problem:
>
> #include <string>
>
> int main()
> {
> std::string s;
>
> s += 0;
> }
>
> Always post code that reproduces the problem. Copy and paste
> the code. Don't type it in.
>
>
> > I can see where adding 0 to
> > something is ambiguous but I'm not trying to do arithmetic. I'm
> > trying to create a string of hex characters.
> > Any suggestions?

>
> As already stated: don't use macros. A macro does not have a type.
> And that's the direct cause of your problem.

 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      11-28-2004
* Jim Lake:
> [top-posting]


Don't top post. Read the FAQ. I have corrected the top-posting
here, but for best chance of useful answers: following usual posting
guidelines such as not top-posting, including relevant code, etc.


* Jim Lake:
> #include <string>
>
> int main()
> {
> std::string s;
>
> s += 0;
> }
>
> c:\documents and settings\administrator.the_domain\my documents\my
> projects\test.cpp(6) : error C2593: 'operator +=' is ambiguous


This is the error message you claimed, so the error seems to have
been successfully reproduced.


> c:\documents and settings\administrator.the_domain\my documents\my
> projects\test.cpp(7) : warning C4508: 'main' : function should return
> a value; 'void' return type assumed


This is an incorrect warning, which means you're using an old compiler.

Try g++.

It's free.


> How is this adding a hex 00 to a string (group) of hex characters?


It isn't, it's what you most probably did.


> I'm looking to add a hex 00 to this: FF FA
>
> I want this-->FF FA to become this--> FF FA 00


To add a string to the end of a std::string you can use the "+="
operator, like this:


std::string s = "FF FA";

s += " 00";

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      11-29-2004

"Alf P. Steinbach" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> #include <string>
>>
>> int main()
>> {
>> std::string s;
>>
>> s += 0;
>> }
>>
>> c:\documents and settings\administrator.the_domain\my documents\my
>> projects\test.cpp(6) : error C2593: 'operator +=' is ambiguous

>
> This is the error message you claimed, so the error seems to have
> been successfully reproduced.
>
>
>> c:\documents and settings\administrator.the_domain\my documents\my
>> projects\test.cpp(7) : warning C4508: 'main' : function should return
>> a value; 'void' return type assumed

>
> This is an incorrect warning, which means you're using an old compiler.
>
> Try g++.
>
> It's free.
>
>
>> How is this adding a hex 00 to a string (group) of hex characters?

>
> It isn't, it's what you most probably did.
>
>
>> I'm looking to add a hex 00 to this: FF FA
>>
>> I want this-->FF FA to become this--> FF FA 00

>
> To add a string to the end of a std::string you can use the "+="
> operator, like this:
>
>
> std::string s = "FF FA";
>
> s += " 00";
>


This is assuming, of course, that Jim, meant that he had a string that
contains "FF FA" when he said that.

It *may* be that what he had was a string that contained two unsigned char
values where the first unsigned char had the hex value FF and the second had
the hex value FA. In that case, appending the hex value 00 (which is just
the single unsigned char with value zero) would be a different task from
appending the string " 00" (which is three unsigned char's: a space
character, followed by two "0" characters).

Jim, can you please clarify which of the above two meanings you had in mind
when you said you had a "string of hex characters"?

-Howard





 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      11-30-2004
"Howard" <(E-Mail Removed)> wrote
> "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> > Jim wrote:
> >> I'm looking to add a hex 00 to this: FF FA
> >>
> >> I want this-->FF FA to become this--> FF FA 00

> >
> > To add a string to the end of a std::string you can use the "+="
> > operator, like this:
> >
> > std::string s = "FF FA";
> > s += " 00";

>
> This is assuming, of course, that Jim, meant that he had a string that
> contains "FF FA" when he said that.
>
> It *may* be that what he had was a string that contained two
> unsigned char values where the first unsigned char had the hex
> value FF and the second had the hex value FA.


Unlikely - on most systems, char is 8-bit and signed,
so a std::string (or a char array) can't contain FF and FA.

Of course, it's hard to know when the guy can't be bothered
posting any code.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple question about hexadecimal values Massi VHDL 1 04-29-2009 10:42 PM
Hexadecimal formatting with leading zeros?! Dmitry Bond. ASP .Net 1 10-13-2005 08:55 AM
std_logic_vector entry as hexadecimal : Different behaviors Sylvain Munaut VHDL 2 12-22-2004 12:19 AM
newbie: Converting Buffer data to Hexadecimal DSKR C Programming 5 06-08-2004 03:01 PM
Hexadecimal to Binary File Conversion Utility Victor Hannak VHDL 0 02-20-2004 08:54 PM



Advertisments