Starting with the address A in the memory of the MK there are N records with the length of k bits each. Records are aligned to the word boundary. Write functions for reading / writing individual bits for any record from this set.
1-word = 4-bytes = 32 bits The question is how to make a record length, for example, not standard 32, but let's say 33 bits or 37 bits? and what operations to use for this?
That's what happened with me, but this is not entirely correct:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <cmath> //extern char tim(char s9[100], int OldSize, int NewSize); extern void _WRITE_MASK1(); extern void _WRITE_MASK2(); extern void _WRITE_BIT(long *j, int num_z, int num_byte, int num_bite, int _vol); extern int _READ_BIT(long *j, int num_z, int num_byte, int num_bite); #define N 1 // ΠΠ²ΠΎΠ΄ ΠΊΠΎΠ»-Π²Π° Π·Π°ΠΏΠΈΡΠ΅ΠΉ ΠΏΠΎ 4 Π±Π°ΠΉΡΠ°. int main() { int K=32; // ΠΠ²ΠΎΠ΄ ΠΊΠΎΠ»-Π²Π° Π±ΠΈΡΠΎΠ² Π² ΠΊΠ°ΠΆΠ΄ΠΎΠΉ Π·Π°ΠΏΠΈΡΠΈ( ΠΎΡ 1 Π΄ΠΎ 32 ) int Z=K-1; if((K<1)||(K>32)) { return 0; } unsigned long mass [N]; for (int i=0; i<N; i++) // ΡΠΎΡΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ Π±ΠΈΡΠΎΠ² Π΄Π»ΠΈΠ½ΠΎΠΉ Π. { if(Z<2) mass[i]=pow(2,Z); if ((Z>=3)&(Z<10)) mass[i]=pow(2,Z)+pow(2,Z-1)+pow(2,Z-2)+1; if ((Z>=10)&(Z<20)) mass[i]=pow(2,Z)+pow(2,Z-2)+pow(2,Z-4)+pow(2,Z-6)+pow(2,Z-8)+i; if ((Z>=20)&(Z<32)) mass[i]=pow(2,Z)+pow(2,Z-4)+pow(2,Z-8)+pow(2,Z-12)+pow(2,Z-16)+i; } _WRITE_MASK1(); _WRITE_MASK2(); int rtf =1; // 0 ΠΈΠ»ΠΈ 1 int bit=1; // ΠΎΡ 0 Π΄ΠΎ 7 int byte=3; ; // ΠΎΡ 0 Π΄ΠΎ 3 int zap=4; // ΠΎΡ 0 Π΄ΠΎ ΠΊΠΎΠ»-Π²Π° Π·Π°ΠΏΠΈΡΠ΅ΠΉ -1 int k=(sizeof(mass))/sizeof(mass[0]); // ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΠΊΠΎΠ»-Π²Π° ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² if(((bit>7)||(bit<0)||(byte>3)||(byte<0)||(zap<0)||(zap>k-1))||((rtf!=0)&(rtf!=1))) { return 0; } _WRITE_BIT(&mass[0],zap,byte,bit,rtf); //zap ΠΎΡ 0 Π΄ΠΎ ΡΠ°Π·ΠΌΠ΅ΡΠ° ΠΌΠ°ΡΡΠΈΠ²Π°-1; byte ΠΎΡ 0 Π΄ΠΎ 4, Π±ΠΈΡ ΠΎΡ 0 Π΄ΠΎ 7. Π£ΡΡΠ°Π½Π°Π²Π»ΠΈΠ²Π°Π΅ΠΌ Π±ΠΈΡ Π² ΠΏΠ°ΠΌΡΡΠΈ ΡΠ°Π²Π½ΡΠΉ rtf int bitRead=1; // ΠΎΡ 0 Π΄ΠΎ 7 int byteRead=3; // ΠΎΡ 0 Π΄ΠΎ 3 int zapRead=4; // ΠΎΡ 0 Π΄ΠΎ ΠΊΠΎΠ»-Π²Π° Π·Π°ΠΏΠΈΡΠ΅ΠΉ -1 if((bitRead>7)||(bitRead<0)||(byteRead>3)||(byteRead<0)||(za pRead<0)||(zapRead>k-1)) { return 0; } int b = _READ_BIT(&mass[0],zapRead,byteRead,bitRead); int c=10; }