Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6001765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:52:53+00:00 2026-05-23T00:52:53+00:00

I need just a little bit of help translating C to python. I have

  • 0

I need just a little bit of help translating C to python. I have not used c++ in about 4 years now, and when I used it, I only new the basics. the context of this snippet is reading a file and creating a checksum

int ff7_checksum( void* qw )
{
   int i = 0, t, d;
   long r = 0xFFFF, len = 4336;
   long pbit = 0x8000;
   char* b=(char*)qw;

   while( len-- ) {
      t = b[i++];
      r ^= t << 8;
      for(d=0;d<8;d++) {
         if( r & pbit )
            r = ( r << 1 ) ^ 0x1021;
         else
            r <<= 1;
      }
      r &= ( 1 << 16 ) - 1;
   }
   return (r^0xFFFF)&0xFFFF;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:52:53+00:00Added an answer on May 23, 2026 at 12:52 am

    I assume that qw points at a buffer with a known size (4336) and that does not really represent a string (i.e. it might contain \0 characters that should still be processed).

    However, in Python (2.x), we still generally model this as a string, since the string may contain embedded \0 bytes, and knows its own length. There is thus also no reason to hard-code the length.

    More idiomatically, we get something like:

    def ff7_checksum(data): # data used to be 'qw'
      all_bits = 0xFFFF # a 16-bit value with all bits set.
      result = all_bits # result used to be 'r'
      pbit = 0x8000 # the highest-order bit in a 16-bit value.
    
      for byte in data: # byte used to be 't'
        result ^= byte << 8
        for i in range(8):
          result = (result << 1) ^ (0x1021 if result & pbit else 0)
        result &= all_bits
      return result ^ all_bits # the original &-mask is not necessary
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a little bit of help here. First off, I am not sure
Just need a little bit of Javascript to warn people that press the back
I am looking for a little bit of help with jqGrid. I have a
I need a little bit of help with using pointers in C++. Sorry to
I have just come a little bit unstuck, I have a list which I
I've just started a project and need a little push in the right direction.
I really just wanted to know a bit more about the PHP Cli with
Bit flags are a little difficult to understand :) I know about this and
I need just dictionary or associative array string => int . There is type
I just need a file (picture, pdf or other type file for printing) of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.