Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved lab1 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions laborator/content/reprezentare-numere/1-convert/convert.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
a.
121 / 2 = 60 r1
60 / 2 = 30 r0
30 / 2 = 15 r0
15 / 2 = 7 r1
7 / 2 = 3 r1
3 / 2 = 1 r1
1 / 2 = 0 r1

121 = 0b 0111 1001
= 0x79



18446 / 2 = 9223 r0
9223 / 2 = 4611 r1
4611 / 2 = 2305 r1
2305 / 2 = 1152 r1
1152 / 2 = 576 r0
576 / 2 = 288 r0
288 / 2 = 144 r0
144 / 2 = 72 r0
72 / 2 = 36 r0
36 / 2 = 18 r0
18 / 2 = 9 r0
9 / 2 = 4 r1
4 / 2 = 2 r0
2 / 2 = 1 r0
1 / 2 = 0 r1

18446 = 0b0100 1000 0000 1110
= 0x480E

b.
50642
47913

c.
0b1011110
0b100101000000001

d.
0x7d
0x8c1f
49 changes: 27 additions & 22 deletions laborator/content/reprezentare-numere/2-len_xor/len_xor.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,36 @@
#include <stdlib.h>
#include <string.h>

int my_strlen(const char *str)
{
/* TODO */

/**
* The cast to (void) is used to avoid a compiler warning. Remove the line
* below to find out what the warning is.
*
* Remove this cast when implementing the function.
*/
(void) str;

return -1;
int my_strlen(const char *str) {
int len = 0;
while (*str) {
len++;
str++;
}
return len - 1;
}

void equality_check(const char *str)
{
/* TODO */
(void) str;
void equality_check(const char *str, int l) {
int i, I;
for (i = 0; i < l; i++) {
I = i + (1 << i);
if (I > l) {
if (*(str + i) % *(str + I))
printf("Address of %c: %p\n", *(str + i), (str + i));
} else if (*(str + i) ^ *(str + I))
printf("Address of %c: %p\n", *(str + i), (str + i));
}
}

int main(void)
{
/* TODO: Test functions */
int main(void) {
char s[100];
int l;

return 0;
}
fgets(s, 100, stdin);
l = my_strlen(s);

printf("length = %d\n", l);
equality_check(s, l);

return 0;
}
28 changes: 19 additions & 9 deletions laborator/content/reprezentare-numere/3-mirror/mirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@
#include <stdlib.h>
#include <string.h>

void mirror(char *s)
{
/* TODO */
(void) s;
void mirror(char *s) {
int l = strlen(s), i, j;
i = 0;
j = l - 1;

char aux;
while (i < j) {
aux = *(s + i);
*(s + i) = *(s + j);
*(s + j) = aux;
i++;
j--;
}
}

int main(void)
{
/* TODO: Test function */
int main(void) {
char sir[] = "Ana n-are mere";

return 0;
}
mirror(sir);
puts(sir);

return 0;
}