Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int BITS_PER_BYTE = 8;
- int result = 0;
- // I would initialize the variable.
- // logic block ...
- int res = result;
- int numBytesInResult = 0;
- while(res != 0)
- {
- numBytesInResult++;
- res = res >> BITS_PER_BYTE;
- }
- char *buf = new char[numBytesInResult + 1];
- buf[numBytesInResult] = '\0';
- for(int i = 0; i < numBytesInResult; i++)
- {
- char c = (char) result & 0xF; // took the last byte of "result" and saved it in "с"
- buf[numBytesInResult - i - 1] = c; // write to buf from the youngest byte to oldest
- result = result >> BITS_PER_BYTE;
- }
- // WriteFile
- delete [] buf;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement