Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Homework 2 Code
//gcc 5.4.0 #include <stdio.h> int DecimalToBinary(int decimal, char *binary) { unsigned int temp = decimal; int i; for (i=0; i<32; i++) { //ASCII code for '0' is 48 and for '1' is 49 //the bit we calculate in this loop is Least Significant Bit (LSB), so the index is 31-i binary[31-i] = 48+ temp % 2; //dividing by 2, simply shifts the number to right and allows us to process the next bit temp = temp / 2; } //an end is put at the end of binary string. Again this is not a number, but an array of '0's and '1's binary [32] = 0; } int main(void) { int k; scanf("%d", &k); char binary[33]; DecimalToBinary(k, binary); int temp; int temp2; int temp3; int temp4; temp = k | 0x000000f0; //#1(a) in homework temp2 = k | 0x00000009; //#1(b) in homework temp3 = k & 0x00ffffff; //#1(c) in homework temp4 = k & 0xffffffff; //#1(d) in homework temp4 = k | 0x0000000a; if ((k|0x00000008)&(k&0xffffffef)) //#1(e) in homework NOT FINISHED { printf("true\n"); } else { printf("false\n"); } DecimalToBinary(k, binary); printf ("Binary: %s\n", binary); DecimalToBinary(temp, binary); printf ("Binary: %s\n", binary); DecimalToBinary(temp2, binary); printf ("Binary: %s\n", binary); DecimalToBinary(temp3, binary); printf ("Binary: %s\n", binary); DecimalToBinary(temp4, binary); printf ("Binary: %s\n", binary); char char_in; //#1(f) on homework char tempChar; scanf("%c",&char_in); if ('a'<=char_in && char_in<='z') { tempChar = char_in - 32; printf("%c",tempChar); } }
run
|
edit
|
history
|
help
0
Conflito de Escrita em Matriz
ctest
Hello, World
main.c
linear hybrid cellular automaton reversible random bit generator stream cipher
Matrix multiplication. C
Refcount220323
Jan23
AVANCE PREGUNTA 3 FICHEROS
Data Types