Re: Concatenating int values

From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 04/21/04


Date: Wed, 21 Apr 2004 08:57:36 +0100

In message <c64vuc$jnn$1@solaris.cc.vt.edu>, Toros Caglar
<tcaglar@vt.edu> writes
>Well I just realized that I am making some assumptions that you might not
>like.. Such as: values are in non-increasing number of digits.. e.g. val1 =
>3 and val2 = 23 would give 53 whereas it should actually give 323..

I think you are confusing value with representation. What you are
describing is an operation on the decimal representation of some integer
values. As both C and C++ (along with most other computer languages)
explicitly do not represent integer values in a decimal form whatever
you do will have to consider changing the representation to the one that
is relevant to the manipulation you wish to do.

The obvious way in C++ is to create a stringstream, feed the values into
it without whitespace and then read an int value out of it. That process
will automate all the conversions for you even if it is not particularly
efficient.

However there is a major question; why do you want to do this? Perhaps
the they should all be strings all the time.

-- 
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


Relevant Pages

  • Re: question regarding java puzzlers #2
    ... it seems a little wrong-headed to me to use an exact representation ... for something that I think is better thought of as an approximation. ... want to convert doubles to BigDecimals using different rules (which is not in ... reason to assume that the true value has a short decimal representation. ...
    (comp.lang.java.programmer)
  • Re: scwewy answers that dont belong
    ... And while the subject of the thread asks if this is an Excel bug, ... it is simply the nature of binary arithmetic in computers that use a ... depending on the precision of the decimal representation, ... it is interesting that a decimal representation ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Bringing back an old tetration curiosity?
    ... For the exp function ... representation of m/n. ... decimal arguments, there can be problems, because the decimal representation ...
    (sci.math)
  • Re: can we find one-way trapdoor funcation family from the theory of calculus
    ... Only if you are doing the evaluation in terms of DECIMALS. ... its REPRESENTATION. ... You are again confusing the concept of number with representation of ...
    (sci.crypt)
  • Re: Identifying an exact binary representation
    ... You'd have to start out with the decimal representation, ... Suppose the decimal representation is ".1234". ... to right till you have a decimal integer. ... lot of smart people in this newsgroup and I wonder they are missing ...
    (comp.lang.fortran)