Created
August 20, 2021 06:58
-
-
Save alsamitech/eb2b5fe1fffab3a1efd83988dfee3ef1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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