-
January 13th, 2008, 12:59 AM
#1
Senior Member
python->pascal
Hi guys,
I have a problem converting a very simple software from python to pascal. I haven't use python before and that is the reason I can't understand some codes. I am attaching the source. But here is what I can't understand:
Code:
def nextDecode(arg1):
global index
result = 0
for i in range(arg1):
rc = shouldDecodeStep(index)
if (rc == -1):
break
else:
if rc:
result = result | 1 << i
index += 1
return result - (1 << arg1 - 1)
First, which is the body of "for" loop? And what does this:
Code:
result = result | 1 << i
Code:
try:
val1 = textbuffer[lindex / 7]
val2 = lindex % 7
return (val1 >> val2 & 1 == 1)
except Exception, e:
return -1
I suppose this is try/except in pascal ?!
What this means? And in nextDecode result is integer.
What does this mean?
And where is the main function of this ?! ... or it hasn't
Last edited by Barov4e; January 13th, 2008 at 03:51 PM.
-
January 13th, 2008, 02:46 AM
#2
Bear in mind I don't know python, but as far as I know python is whitespace sensitive. That would lead me to believe that the following is the body of the for loop:
Code:
rc = shouldDecodeStep(index)
if (rc == -1):
break
else:
if rc:
result = result | 1 << i
index += 1
As for the following:
Code:
result = result | 1 << i
| is normally the bitwise or operator, and << generally means shift the left side of the operator by the value on the right side. To understand what it does you need to know the precedence of the operators. i.e. does it mean:
Code:
result = (result | 1) << i
or
result | (1 << i)
Assuming the former, here's an example of what it does:
Code:
result = 5 (0101)
i = 1 (0001)
5 | 1 = 5
0101
0001
0101
5 << 1 = 10
1010 (all bits have moved left one place)
Hope that helps a bit.
ac
-
January 13th, 2008, 03:52 PM
#3
Senior Member
Code:
result = result | 1 << i
I understan this, but how can I realize it in Pascal. Is there some sort of function?
-
January 13th, 2008, 04:21 PM
#4
Sorry, I misunderstood. If you do a search on google for "pascal bitwise operator" the first link takes you to a page with explanations of the bitwise operators. Maybe try doing a search next time before posting questions.
To answer your question, I believe the following will do what you want (assuming pascal and python have the same rules for operator precedence):
Code:
result := result or 1 shl i;
Don't quote me on it though since it's been years since I've even looked at pascal. You should search for a pascal tutorial or something because you don't seem to understand the basics.
ac
-
January 13th, 2008, 05:50 PM
#5
Senior Member
Thanks, I'll check it. I just didn't think of searching for pascal bitwise operators
-
January 14th, 2008, 01:52 AM
#6
Don't worry about it - there's nothing wrong with asking questions, I just got a bit cranky.
ac
Similar Threads
-
By HTRegz in forum General Computer Discussions
Replies: 0
Last Post: September 19th, 2006, 07:28 PM
-
By HTRegz in forum The Security Tutorials Forum
Replies: 12
Last Post: January 28th, 2006, 08:02 PM
-
By HTRegz in forum Other Tutorials Forum
Replies: 20
Last Post: September 10th, 2005, 07:28 AM
-
By PacketThirst in forum Other Tutorials Forum
Replies: 2
Last Post: August 14th, 2005, 07:16 PM
-
By [pHA]XeNoCiDe in forum AntiOnline's General Chit Chat
Replies: 11
Last Post: July 8th, 2002, 07:56 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|