Created
December 30, 2020 15:24
-
-
Save Its-Just-Nans/52a886b47fe51e929152394fbdf3376a to your computer and use it in GitHub Desktop.
Function to print the byte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
void printByte(unsigned int* byte){ | |
int length = sizeof(*byte); | |
length = length * 8; | |
//printf("%d %d\n", length, *byte); | |
for(int count = 0; count < length; count ++){ | |
unsigned int temp = (*byte)<<(count); | |
printf("%d ", temp>>(length-1)); | |
} | |
} | |
uint8_t main(){ | |
unsigned int temp; | |
temp = 128; | |
printByte(&temp); | |
return 0; | |
} | |
//note that the type can be changed like this | |
/* | |
void printByte(uint8_t* byte){ | |
int length = sizeof(*byte); | |
length = length * 8; | |
//printf("%d %d\n", length, *byte); | |
for(int count = 0; count < length; count ++){ | |
uint8_t temp = (*byte)<<(count); | |
printf("%d ", temp>>(length-1)); | |
} | |
} | |
*/ | |
//if the type is not unsigned, there will be "-1" and not "1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result :