Skip to content

Instantly share code, notes, and snippets.

@alsamitech
Created August 20, 2021 06:58
Show Gist options
  • Save alsamitech/eb2b5fe1fffab3a1efd83988dfee3ef1 to your computer and use it in GitHub Desktop.
Save alsamitech/eb2b5fe1fffab3a1efd83988dfee3ef1 to your computer and use it in GitHub Desktop.
void reverse_bytes(char* restrict bytes, const size_t len){
for(size_t i=0;i<len/2;i++){
char tmp=bytes[i];
bytes[i]=bytes[len-1-i];
bytes[len-1-i]=tmp;
}
}
// str must have 11 bytes allocated to it
void int_to_str(int val, char* str){
if(val<0)val=-val,*str++='-';
size_t i=0;
while(val){
char c=val%10;
str[i++]=c+'0';
val-=c,val/=10;
}
str[i]=0;
reverse_bytes(str, i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment