How many bytes in a JavaScript string?

You can use the Blob to get the string size in bytes. Examples: console.info( new Blob([‘😂’]).size, // 4 new Blob([‘👍’]).size, // 4 new Blob([‘😂👍’]).size, // 8 new Blob([‘👍😂’]).size, // 8 new Blob([‘I\’m a string’]).size, // 12 // from Premasagar correction of Lauri’s answer for // strings containing lone characters in the surrogate pair range: // … Read more

Correct way to convert size in bytes to KB, MB, GB in JavaScript

From this: (source) Unminified and ES6’ed: (by the community) function formatBytes(bytes, decimals = 2) { if (!+bytes) return ‘0 Bytes’ const k = 1024 const dm = decimals < 0 ? 0 : decimals const sizes = [‘Bytes’, ‘KB’, ‘MB’, ‘GB’, ‘TB’, ‘PB’, ‘EB’, ‘ZB’, ‘YB’] const i = Math.floor(Math.log(bytes) / Math.log(k)) return `${parseFloat((bytes / … Read more

Convert integer into byte array (Java)

Have a look at the ByteBuffer class. ByteBuffer b = ByteBuffer.allocate(4); //b.order(ByteOrder.BIG_ENDIAN); // optional, the initial order of a byte buffer is always BIG_ENDIAN. b.putInt(0xAABBCCDD); byte[] result = b.array(); Setting the byte order ensures that result[0] == 0xAA, result[1] == 0xBB, result[2] == 0xCC and result[3] == 0xDD. Or alternatively, you could do it manually: … Read more

Convert bytes to int?

Assuming you’re on at least 3.2, there’s a built in for this: int.from_bytes( bytes, byteorder, *, signed=False ) … The argument bytes must either be a bytes-like object or an iterable producing bytes. The byteorder argument determines the byte order used to represent the integer. If byteorder is “big”, the most significant byte is at … Read more

How to Get True Size of MySQL Database?

From S. Prakash, found at the MySQL forum: SELECT table_schema “database name”, sum( data_length + index_length ) / 1024 / 1024 “database size in MB”, sum( data_free )/ 1024 / 1024 “free space in MB” FROM information_schema.TABLES GROUP BY table_schema; Or in a single line for easier copy-pasting: SELECT table_schema “database name”, sum( data_length + … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)