-
- memset(id->buf, 0, byteSize-1);
- id->buf[byteSize-1] = val;
+ memset(id->buf, 0, byteSize);
+ data = data << unusedBits;
+
+ /*Now, seggregate the value into 'byteSize' number of Octets in sequence:
+ * 1. Pull out a byte of value (Starting from MSB) and put in the 0th Octet
+ * 2. Fill the buffer/String Octet one by one until LSB is reached*/
+ for(byteIdx = 1; byteIdx <= byteSize; byteIdx++)
+ {
+ tmp = (uint64_t)0xFF;
+ tmp = (tmp << (8 * (byteSize - byteIdx)));
+ tmp = (data & tmp) >> (8 * (byteSize - byteIdx));
+ id->buf[byteIdx - 1] = tmp;
+ }