Find Jobs
Hire Freelancers

Convert 51 lines of C to Python

$15-20 USD

Đã hoàn thành
Đã đăng vào gần 17 năm trước

$15-20 USD

Thanh toán khi bàn giao
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.
Mã dự án: 2963039

Về dự án

3 đề xuất
Dự án từ xa
Hoạt động 17 năm trước

Bạn muốn kiếm tiền?

Lợi ích khi chào giá trên Freelancer

Thiết lập ngân sách và thời gian
Nhận thanh toán cho công việc
Phác thảo đề xuất của bạn
Miễn phí đăng ký và cháo giá cho công việc
Đã trao cho:
Avatar người dùng
See private message.
$17 USD trong 7 ngày
5,0 (43 nhận xét)
4,4
4,4
3 freelancer chào giá trung bình $17 USD cho công việc này
Avatar người dùng
See private message.
$17 USD trong 7 ngày
4,9 (453 nhận xét)
7,5
7,5
Avatar người dùng
See private message.
$17 USD trong 7 ngày
0,0 (0 nhận xét)
0,0
0,0

Về khách hàng

Cờ của UNITED STATES
United States
5,0
1
Thành viên từ thg 2 24, 2004

Xác thực khách hàng

Cảm ơn bạn! Chúng tôi đã gửi email chứa đường link để bạn lấy tín dụng miễn phí.
Đã xảy ra lỗi trong khi gửi email của bạn. Hãy thử lại.
Người Dùng Đã Đăng Ký Tổng Số Việc Đã Đăng
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Đang tải xem trước
Đã cấp quyền truy cập vị trí.
Phiên đăng nhập của bạn đã hết hạn và bạn đã bị đăng xuất. Hãy đăng nhập lại.