Find Jobs
Hire Freelancers

Convert 51 lines of C to Python

$15-20 USD

Завершено
Опублікований almost 17 years ago

$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 yrs ago

Хочете заробити?

Переваги подання заявок на 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
На сайті з лют. 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)
Завантажуємо для перегляду
Дозвіл на визначення геолокації надано.
Ваш сеанс входу закінчився, і сеанс було закрито. Будь ласка, увійдіть знову.