473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Few lines of C++ to PHP

Hey,

How would i do this in php ? (from borland c++)

for (int i=1; i<=myString.Length(); ++i)
{
returnValue += StrToInt(AnsiString("0x" +
(AnsiString)myString[i]));
}
--
thanks
Paul
www.pjenkins.co.uk

Jan 5 '07 #1
5 1114
I think you are trying to convert hexadecimal number to decimal, then
add them together.
<?php
$temp = str_split($myString);
$returnValue = 0;
foreach($temp as $each) $returnValue += hexdec($each);
?>

Hope that helps

Hendri Kurniawan

je******@gmail.com wrote:
Hey,

How would i do this in php ? (from borland c++)

for (int i=1; i<=myString.Length(); ++i)
{
returnValue += StrToInt(AnsiString("0x" +
(AnsiString)myString[i]));
}
--
thanks
Paul
www.pjenkins.co.uk
Jan 5 '07 #2
>How would i do this in php ? (from borland c++)
for (int i=1; i<=myString.Length(); ++i)
{
returnValue += StrToInt(AnsiString("0x" +
(AnsiString)myString[i]));
}
Try something like this:

<?
$returnValue = 0;
$myString = 'ABCDEF';

for ($i=1;$i<=strlen($myString);$i++)
{
$returnValue += hexdec($myString[$i]);
}

echo $returnValue;
?>

Regards,
Chris
Jan 5 '07 #3
Correction to my code:
>for ($i=1;$i<=strlen($myString);$i++)
That should be:

for ($i=0;$i<strlen($myString);$i++)

(I didn't realise string indexes started at 1 in C and not 0 like PHP)

Chris

Jan 5 '07 #4
Thats perfect,
thank you :)

paul
Skeleton Man wrote:
Correction to my code:
for ($i=1;$i<=strlen($myString);$i++)

That should be:

for ($i=0;$i<strlen($myString);$i++)

(I didn't realise string indexes started at 1 in C and not 0 like PHP)

Chris
Jan 5 '07 #5
..oO(Skeleton Man)
>for ($i=0;$i<strlen($myString);$i++)
Just a general performance note: In this case strlen() will be called
again in each iteration, which can become an issue in a long-running
loop or with a more complex expression.

The value to check against should be put in a variable instead before
entering the loop, e.g.

for ($i = 0, $l = strlen($myString); $i < $l; $i++) {
...
}

Micha
Jan 5 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jesse Noller | last post by:
I am a relative newbie to python and I am having issues trying to iterate over the lines of a file. I have a text file - foo.bar inside of this file are lines of text: x-3411342 y-1324123...
5
by: Brian | last post by:
Hello all.. Am working on an Air Hockey game... have an table loaded into a picture box. The borders of the table are slightly slanted. Am using hit testing lines with GDI+ to manipulate the...
2
by: m00nm0nkey | last post by:
Ok well i thought i'd try a different approach, so what I'm now trying is appending 50,000 lines from the collection to a stringbuilder, and then writing that entire stringbuilder to a file. ...
11
by: lovecreatesbeauty | last post by:
For example, line L1 and line L2 are two lines in two-dimensional space, the start-points and end-points can be described with following the `point_t' type. The start-points and end-points are:...
82
by: Edward Elliott | last post by:
This is just anecdotal, but I still find it interesting. Take it for what it's worth. I'm interested in hearing others' perspectives, just please don't turn this into a pissing contest. I'm in...
24
by: rudranee | last post by:
hi there, can anyone tell me how to lines from a file which are odd numbered i.e. 1st,3rd,5th...lines. i tried incrementing file pointer by 2 (fp=fp+2) but it does'nt work Can someone give me...
11
by: Girish Sahani | last post by:
I wrote the following code to concatenate every 2 keys of a dictionary and their corresponding values. e.g if i have tiDict1 = tiDict1 = {'a':,'b':} i should get tiDict2={'ab':} and similarly for...
7
by: peraklo | last post by:
Hello, there is another problem i am facing. i have a text file which is about 15000 lines big. i have to cut the last 27 lines from that file and create a new text file that contans those 27...
19
by: Pavan | last post by:
Hi, I want to know if there is any software for measuring lines of code of my c++ application. I found out a tool, sloccount, but it gives only physical lines of code. I found out one more...
7
by: Gustaf | last post by:
Hi all, Just for fun, I'm working on a script to count the number of lines in source files. Some lines are auto-generated (by the IDE) and shouldn't be counted. The auto-generated part of files...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.