Skip to content

Commit

Permalink
daily upload 5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
TGSpock123 committed May 8, 2024
1 parent 5061d81 commit 0cd0179
Show file tree
Hide file tree
Showing 64 changed files with 1,506 additions and 56 deletions.
19 changes: 19 additions & 0 deletions 15/15.1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
int main (void)
{
int val = 2, val2 = 3, val3 = 7;
unsigned char val1 = 2;

val3 &= val2;
~val1;
printf ("%d, %u, %d, %d\n", ~val, ~val1, val & val2, val3);

val = 5;
val3 |= val;
printf ("%d \n", val3);

val3 = 5;
val3 ^= val;
printf ("%d \n", val3);
return 0;
}
Binary file added 15/15.1.exe
Binary file not shown.
60 changes: 60 additions & 0 deletions 15/15.10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "15.9_10.h"

int main (int argc, char * argv[])
{
bool eigen = 1;
int j, p;
char ch [5][33];

if (argc < 3)
{
printf ("No enough parameters. \n");
exit (0);
}

for (int i = 0; i < strlen (argv[1]); i ++)
{
if ((argv[1][i] != '0') && (argv[1][i] != '1'))
{
eigen = 0;
break;
}
}

if (eigen == 1)
{
j = b2dcov (argv[1]);
}else
{
printf ("Wrong input");
exit (0);
}

for (int i = 0; i < strlen (argv[2]); i ++)
{
if ((argv[2][i] != '0') && (argv[2][i] != '1'))
{
eigen = 0;
break;
}
}

if (eigen == 1)
{
p = b2dcov (argv[2]);
}else
{
printf ("Wrong input");
exit (0);
}

printf ("~ %s = %s\n", argv [1], itobs (~ j, ch[0]));
printf ("~ %s = %s\n", argv [2], itobs (~ p, ch[1]));
printf ("%s & %s = %s\n", argv[1], argv[2], itobs (j & p, ch[2]));
printf ("%s | %s = %s\n", argv[1], argv[2], itobs (j | p, ch[3]));
printf ("%s ^ %s = %s\n", argv[1], argv[2], itobs (j ^ p, ch[4]));
printf ("%d bits in %s open. \n", bits_open (j), argv[1]);
printf ("%d bits in %s open. \n", bits_open (p), argv[2]);

return 0;
}
Binary file added 15/15.10.exe
Binary file not shown.
42 changes: 42 additions & 0 deletions 15/15.11.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "15.11.h"

int main (int argc, char * argv[])
{
int j, p;
char th[3];

if (argc < 3)
{
printf ("No enough parameters. \n");
exit (0);
}

j = str2int (argv[1]);
p = str2int (argv[2]);

if ((p > 32) || (p <= 0))
{
printf ("Bits are to %s. \n", (p > 32) ? "more" : "less");
exit (0);
}

switch (p)
{
case 1:
strcpy (th, "st\0");
break;
case 2:
strcpy (th, "nd\0");
break;
case 3:
strcpy (th, "rd\0");
break;
default:
strcpy (th, "th\0");
break;
}

printf ("%d's %d%s bit is %s. \n", j, p, th, (if_open (j, p)) ? "opened" : "closed");

return 0;
}
Binary file added 15/15.11.exe
Binary file not shown.
24 changes: 24 additions & 0 deletions 15/15.11.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int str2int (char * ch)
{
int ret = 0;

for (int i = 0; i < strlen (ch); i ++)
{
ret *= 10;
ret += (ch[i] - 48);
}

return ret;
}

_Bool if_open (int j, int p)
{
int mask;

mask = 1 << (p - 1);
return ((j & mask) == mask) ? 1 : 0;
}
43 changes: 43 additions & 0 deletions 15/15.12.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <stdio.h>

unsigned int rotate_1 (unsigned int j, unsigned int p);

int main (void)
{
unsigned int j, p;

printf ("Please enter a number to convert: \n");
scanf ("%u", &j);
while (getchar() != '\n');
printf ("Please enter how many bits to convert: \n");
scanf ("%u", &p);
while (getchar() != '\n');

printf ("The number converted is %u. \n", rotate_1 (j, p));

return 0;
}

unsigned int rotate_1 (unsigned int j, unsigned int p)
{
unsigned int temp = 1 << p;
unsigned int j1, p1 = j, count = 0, mask = 0;

for (; p1 > 0; p1 >>= 1, count ++);

if (count < p)
{
return 0;
}

for (int i1 = 0, i2 = 1; i1 < (count - p); i1 ++, i2 <<= 1)
{
mask += i2;
}

for (j1 = j; j1 > temp; j1 >>= 1);
j &= mask;
j <<= p;

return j1 + j;
}
19 changes: 19 additions & 0 deletions 15/15.13.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "15.13_14.h"

int main (void)
{
union font_para_in2ways
{
struct font_para font_para_instruct;
unsigned int font_para_inuint;
};

union font_para_in2ways set_font = {
1, 12, 0, 0, 0, 0
};

print_para (&set_font.font_para_instruct);
put_menu (&set_font.font_para_instruct);

return 0;
}
Loading

0 comments on commit 0cd0179

Please sign in to comment.