Find Jobs
Hire Freelancers

Convert 51 lines of C to Python

$15-20 USD

Concluído
Publicado há aproximadamente 17 anos

$15-20 USD

Pago na entrega
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 do Projeto: 2963039

Sobre o projeto

3 propostas
Projeto remoto
Ativo há 17 anos

Quer ganhar algum dinheiro?

Benefícios de ofertar no Freelancer

Defina seu orçamento e seu prazo
Seja pago pelo seu trabalho
Descreva sua proposta
É grátis para se inscrever e fazer ofertas em trabalhos
Concedido a:
Avatar do Usuário
See private message.
$17 USD em 7 dias
5,0 (43 avaliações)
4,4
4,4
3 freelancers estão ofertando em média $17 USD for esse trabalho
Avatar do Usuário
See private message.
$17 USD em 7 dias
4,9 (453 avaliações)
7,5
7,5
Avatar do Usuário
See private message.
$17 USD em 7 dias
0,0 (0 avaliações)
0,0
0,0

Sobre o cliente

Bandeira do(a) UNITED STATES
United States
5,0
1
Membro desde fev. 24, 2004

Verificação do Cliente

Obrigado! Te enviamos um link por e-mail para que você possa reivindicar seu crédito gratuito.
Algo deu errado ao enviar seu e-mail. Por favor, tente novamente.
Usuários Registrados Total de Trabalhos Publicados
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Carregando pré-visualização
Permissão concedida para Geolocalização.
Sua sessão expirou e você foi desconectado. Por favor, faça login novamente.