Pyton newbie here, but programming in one language or another 50 years. Someone who’s opinion I trust said I should look into python because of it’s rapid development characteristics,which I prize. I’ve taken a 12 hour on-line tutorial and a couple of ‘learn by doing’ projects type tutorials.
No tutorial covers anything close to what I’m trying to do, which I’ve been doing in C, the project is pretty big, reading and writing to an SD disk-image for vintage 70/80’s computer. But no matter how big the project is, it’s still comprised of small functions, and it’s just one of these small functions I choose to start with.
They are DEC type rad50 calls “pack” and “unpack”, and in C look like this:
There’s endian, byte and word data type issues, along with some bit twiddling that none of the python tutorials covered..
My questions are:
1. Is python still a good choice for these types of projects?
2. Can anyone point to helpful tutorials for either the rad50 routines or disk-image file reading/writing?
3. Anyone have any other helpful pionts
No tutorial covers anything close to what I’m trying to do, which I’ve been doing in C, the project is pretty big, reading and writing to an SD disk-image for vintage 70/80’s computer. But no matter how big the project is, it’s still comprised of small functions, and it’s just one of these small functions I choose to start with.
They are DEC type rad50 calls “pack” and “unpack”, and in C look like this:
// "0000000000111111111122222222223333333333" tens row // "0123456789012345678901234567890123456789" ones row static char r50[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ.$%0123456789"; // Rad50 character array // *** "chrs" MUST be a three cell array, "r50" is always 40 cell array *** int srch(char chr) { // search r50 array for character and return character's position int i; // array index for(i=0; i<39; i++) { // search 40 characters of "r50" for "chr" if(r50[i] == chr) { // if "chr" = character @ "r50" position "i" return i; // return found "r50" index } // end if "chr" = character @ "r50" position "i" } // end search 40 characters of "r50" for "chr" return 645001; // return illegal character flag } // end search r50 array for character and return character's position // pack example // char chrs[3]= "tom"; // setup three character array // unsigned short packed; // unsigned short to pack three "chrs" into // pack(packed, chr); // // *** pack firct 3 character string "chr", returned into "pack()" unsigned short *** unsigned short pack(char *chrs) { // rad50 character pack routine int pacc = 0; // int for packed word int pac = 0; // int for packed word pac = srch(toupper(chrs[0])); // get pack value of ascii character if(pac==64001) {return 64001;} // found non-rad50 character pacc = pacc + (pac * (050 * 050)); // left shift character over three places pac = srch(toupper(chrs[1])); // get pack value of ascii character two if(pac==64001) {return 64001;} // get pack value of ascii character pacc = pacc + (pac * 050); // left shift character over two places pac = srch(toupper(chrs[2])); // get pack value of ascii character three if(pac==64001) {return 64001;} // get pack value of ascii character pacc = pacc + pac; // place character in first character place return pacc; // return packed number } // end rad50 character pack routine // *** unpack - converts RAD50 packed "word" to three "chrs" of ASCII *** void unpack(unsigned short word, char *chrs) // pointer to character array[3] { // start unpack word block if (word < 0175000) { // if word is legal RAD50 word < 64,000? chrs[0] = r50[word / 050*050]; // to get first character, packed num / (o50 xo50) chrs[1] = r50[(word / 050) % 050]; // to get second character, (packed num / o50) mod o50) chrs[2] = r50[word % 050]; // to get third character, (packed num mod o50) } else // if word is NOT legal RAD50 word > 64,000? chrs[0] = chrs[1] = chrs[2] = ' '; // set 3 characters of array to ' ' } // end unpack word block // pack and unpack examples //char chr[3]="tom"; // set RAD50 chars //unsigned short packed; // packed 3 character string //packed = pack(chr); // pack 3 character string "chr" //printf("unpacked number is: %d\n", packed); // print promt //unpack(packed); // unpack "packed" into 3 character string "chr" //printf("unpacked number is: %c\n", chr[0]); // print promt //printf("unpacked number is: %c\n", chr[1]); // print promt //printf("unpacked number is: %c\n", chr[2]); // print promtfThese routines are expanded for better operation understanding and debugging.
There’s endian, byte and word data type issues, along with some bit twiddling that none of the python tutorials covered..
My questions are:
1. Is python still a good choice for these types of projects?
2. Can anyone point to helpful tutorials for either the rad50 routines or disk-image file reading/writing?
3. Anyone have any other helpful pionts
Larz60+ write Jun-03-2024, 11:09 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
works for C code as well, I added tags for you this post.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
works for C code as well, I added tags for you this post.