Find Jobs
Hire Freelancers

Convert 51 lines of C to Python

$15-20 USD

已完成
已发布将近 17 年前

$15-20 USD

货到付款
Convert 51 lines of code from C to python. Results must be bit-for-bit identical with that of the following code and must be fast and efficient as the methods will be called perhaps several hundred times per second. It should use a buffer class of some sort with putInt() and putUint() methods and getInt() and getUint() methods that pop stuff off the buffer. Please see the attached text file which includes the 51 lines of code that need converting, an example of the tests I would like it to pass, and an example of the usage of the resulting class. ## Deliverables Working code in a single .py file with tests, output, and access methods as described in the description section and attached file. It is important that the actual data be stored in a string that is bit-for-bit identical to the representation of the data in the C code being converted as the resulting code will be incorporated into a game sending the data to the program written in C. Your code should work more or less as follows: b = sauerBuffer() [login to view URL](sauerConst['SV_INITS2C']) [login to view URL]([login to view URL]) [login to view URL](252) # Protocol Version [login to view URL](4) print repr([login to view URL]) ## Testing Your code, complete with an example testing getint and getuint and putint putuint to test all values within their respective ranges. Test should probably be similar to the following: def test_int(self): b = 2 ** 31 lower_bound = -b upper_bound = b i = lower_bound while i < upper_bound: p = sauerBuffer() try: [login to view URL](i) except: print "could not putint ", i if([login to view URL]() != i): print "FAILED ", i i+= 1 def test_uint(self): b = 2 ** 28 lower_bound = 0 upper_bound = b i = lower_bound while i < upper_bound: p = sauerBuffer() try: [login to view URL](i) except: print "could not putuint ", i if([login to view URL]() != i): print "FAILED ", i i+= 1 ## The code you are converting From C to python: void putint(ucharbuf &p, int n) { if(n<128 && n>-127) [login to view URL](n); else if(n<0x8000 && n>=-0x8000) { [login to view URL](0x80); [login to view URL](n); [login to view URL](n>>8); } else { [login to view URL](0x81); [login to view URL](n); [login to view URL](n>>8); [login to view URL](n>>16); [login to view URL](n>>24); } } int getint(ucharbuf &p) { int c = (char)[login to view URL](); if(c==-128) { int n = [login to view URL](); n |= char([login to view URL]())<<8; return n; } else if(c==-127) { int n = [login to view URL](); n |= [login to view URL]()<<8; n |= [login to view URL]()<<16; return n|([login to view URL]()<<24); } else return c; } // much smaller encoding for unsigned integers up to 28 bits, but can handle signed void putuint(ucharbuf &p, int n) { if(n < 0 || n >= (1<<21)) { [login to view URL](0x80 | (n & 0x7F)); [login to view URL](0x80 | ((n >> 7) & 0x7F)); [login to view URL](0x80 | ((n >> 14) & 0x7F)); [login to view URL](n >> 21); } else if(n < (1<<7)) [login to view URL](n); else if(n < (1<<14)) { [login to view URL](0x80 | (n & 0x7F)); [login to view URL](n >> 7); } else { [login to view URL](0x80 | (n & 0x7F)); [login to view URL](0x80 | ((n >> 7) & 0x7F)); [login to view URL](n >> 14); } } int getuint(ucharbuf &p) { int n = [login to view URL](); if(n & 0x80) { n += ([login to view URL]() << 7) - 0x80; if(n & (1<<14)) n += ([login to view URL]() << 14) - (1<<14); if(n & (1<<21)) n += ([login to view URL]() << 21) - (1<<21); if(n & (1<<28)) n |= 0xF0000000; } return n; ## Platform It should run anywhere python does. Making use of Cheese shop modules is AOK.
项目 ID: 2963039

关于此项目

3提案
远程项目
活跃17 年前

想赚点钱吗?

在Freelancer上竞价的好处

设定您的预算和时间范围
为您的工作获得报酬
简要概述您的提案
免费注册和竞标工作
颁发给:
用户头像
See private message.
$17 USD 在7天之内
5.0 (43条评论)
4.4
4.4
3威客以平均价$17 USD来参与此工作竞价
用户头像
See private message.
$17 USD 在7天之内
4.9 (453条评论)
7.5
7.5
用户头像
See private message.
$17 USD 在7天之内
0.0 (0条评论)
0.0
0.0

关于客户

UNITED STATES的国旗
United States
5.0
1
会员自2月 24, 2004起

客户认证

谢谢!我们已通过电子邮件向您发送了索取免费积分的链接。
发送电子邮件时出现问题。请再试一次。
已注册用户 发布工作总数
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
加载预览
授予地理位置权限。
您的登录会话已过期而且您已经登出,请再次登录。