Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help for Pascal Translation from C Posted by mcruli on 6 Apr 2010 at 2:27 PM
Hi for all,

I need translata a funcion from C to pascal

#define TMaskClear(E, M) ((M)[(E)/8] &= ~(1 << ((E)%8)))

"E" is Integer
"M" is TMask :
Type TMask = Array[0..64] of Byte;


This part is a Matrix asignation :
(M)[(E)/8]
Okay,

¿and this part?
&= ~(1 << ((E)%8))

For example :
If you use this funcion in C :
(First All set to $FF)
[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]


Executing this funcion for E=61 (3D hex)
[255,255,255,255,255,255,255,223,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]

In the index "7" the value change to 223.

Mc
Report
Re: Help for Pascal Translation from C Posted by _Atex_ on 6 Apr 2010 at 7:40 PM
This works with your example, not sure how will perform w/ different values though, since I didn't test it
type tmask=array[0..64] of byte;

var m:tmask;

procedure tmaskclear(e:integer;var n:tmask);
 begin
  n[e div 8]:=n[e div 8] and not(1 shl (e mod 8));
 end;

begin
 fillchar(m,sizeof(m),$ff);

 tmaskclear(61,m);

 writeln(m[7]);
 readln;
end.

Report
Re: Help for Pascal Translation from C Posted by mcruli on 7 Apr 2010 at 12:06 PM
Works perfect,

Thanks!!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.