/ contracts / lib / Bytes32Lib.sol
Bytes32Lib.sol
 1  pragma solidity ^0.4.0;
 2  
 3  library Bytes32Lib {
 4  
 5      function toString(bytes32 self) internal constant returns (string) {
 6          bytes memory bytesString = new bytes(32);
 7          uint charCount = 0;
 8          for (uint j = 0; j < 32; j++) {
 9              byte char = byte(bytes32(uint(self) * 2 ** (8 * j)));
10              if (char != 0) {
11                  bytesString[charCount] = char;
12                  charCount++;
13              }
14          }
15          bytes memory bytesStringTrimmed = new bytes(charCount);
16          for (j = 0; j < charCount; j++) {
17              bytesStringTrimmed[j] = bytesString[j];
18          }
19          return string(bytesStringTrimmed);
20      }
21      
22  
23      
24      
25  }