diff --git a/laborator/content/reprezentare-numere/1-convert/convert.txt b/laborator/content/reprezentare-numere/1-convert/convert.txt new file mode 100644 index 00000000..a1c3e037 --- /dev/null +++ b/laborator/content/reprezentare-numere/1-convert/convert.txt @@ -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 \ No newline at end of file diff --git a/laborator/content/reprezentare-numere/2-len_xor/len_xor.c b/laborator/content/reprezentare-numere/2-len_xor/len_xor.c index 8e45ecbd..09ec009f 100644 --- a/laborator/content/reprezentare-numere/2-len_xor/len_xor.c +++ b/laborator/content/reprezentare-numere/2-len_xor/len_xor.c @@ -2,31 +2,36 @@ #include #include -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; +} diff --git a/laborator/content/reprezentare-numere/3-mirror/mirror.c b/laborator/content/reprezentare-numere/3-mirror/mirror.c index 513c0ab4..ade5bf92 100644 --- a/laborator/content/reprezentare-numere/3-mirror/mirror.c +++ b/laborator/content/reprezentare-numere/3-mirror/mirror.c @@ -2,16 +2,26 @@ #include #include -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; +} \ No newline at end of file