How to get the same values in Python as in C++?
CPP code
#include <bitset>
#include <iostream>
using namespace std;
int main() {
short int divider = -32768;
auto divider_bin_str = bitset<16>(divider).to_string();
cout << "divider: " << divider << " " << divider_bin_str << endl; // divider: -32768 1000000000000000
char division = static_cast<char>(divider % 3000);
string division_bin_str = bitset<8>(division).to_string();
cout << "division: " << (int) division << " " << division_bin_str << endl; // division: 48 00110000
}
Python code
divider = -32768
print(f'divider: {divider} {bin(divider)}') # divider: -32768 -0b1000000000000000
division = divider % 3000
print(f'division: {division} {bin(division)}') # division: 232 0b11101000
I couldn't think of anything better than calling C code from Python :)