MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / pad

Function pad

Hashes/SHA1.js:21–27  ·  view source on GitHub ↗

* Adds padding to binary/hex string representation * * @param {string} str - string representation (binary/hex) * @param {int} bits - total number of bits wanted * @return {string} - string representation padding with empty (0) bits * * @example * pad("10011", 8); // "00010011"

(str, bits)

Source from the content-addressed store, hash-verified

19 * pad("10011", 8); // "00010011"
20 */
21function pad(str, bits) {
22 let res = str
23 while (res.length % bits !== 0) {
24 res = '0' + res
25 }
26 return res
27}
28
29/**
30 * Separates string into chunks of the same size

Callers 2

preProcessFunction · 0.70
SHA1Function · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected