Z create byte sized binary string from a integer
This is a algorithm I found useful when writing a emulator. It converts a integer into a byte sized binary string. Catches overflows , and automaticly adds the empty 0's which itoa does not do.
AI
Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Codice sorgente
void createbinarystring(int value, char* string)
{
if(value > 255)
{
strcpy(string,"* overflow");
return;
}
char ibuff[10];
itoa(value,ibuff,2);
int len;
len = strlen(ibuff);
if(len < 8)
{
int space = 8-len;
for(int i = 0; i < space; i++)
{
string[i] = '0';
}
string[space] = 0;
strcat(string,ibuff);
return;
}
else if(len == 8)
{
strcpy(string,ibuff);
return;
}
strcpy(string,"unknown");
}
Upload
Commenti originali (3)
Recuperato da Wayback Machine