Skip to content

Instantly share code, notes, and snippets.

@Its-Just-Nans
Created December 30, 2020 15:24
Show Gist options
  • Save Its-Just-Nans/52a886b47fe51e929152394fbdf3376a to your computer and use it in GitHub Desktop.
Save Its-Just-Nans/52a886b47fe51e929152394fbdf3376a to your computer and use it in GitHub Desktop.
Function to print the byte
#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"
@Its-Just-Nans
Copy link
Author

Result :

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 

@Its-Just-Nans
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment