Convert images, photos, and text to binary with ease.
Get StartedIt couldn't be easier
When the page loads, the JavaScript code sets a default conversion type to 'Decimal to Binary' using the line document.getElementById('conversionType').value = 'decToBin';
. This ensures that if the user hasn't selected a conversion type, the application will default to this option. The main function that processes the conversion is convert()
, which is called when the user clicks the 'Convert' button. This function checks which conversion type is selected from the dropdown menu and performs the corresponding conversion.
There are multiple conversion functions designed to handle different types of data conversions, such as text, binary, images, and more:
imageToBinary()
function takes an image input, reads it using a FileReader
object, and converts the image into a binary format. The image is read as a Base64 encoded string, and each character of the string is converted into its corresponding binary value.binaryToImage()
function converts a binary string (such as the output from the previous conversion) back into an image. It splits the binary string into chunks, converts each chunk back to its corresponding character, and reassembles the image data. This data is then used to generate an HTML <img>
tag, allowing the user to view the image again.textToBinary()
function takes user input in the form of text and converts each character into its binary representation. Each character's Unicode code point is converted into a binary string, and these are combined to form the full binary representation of the input text.binaryToText()
function reverses the binary-to-text process. It splits a binary input string into chunks, converts each chunk back into its corresponding decimal value, and then uses that value to determine the character (using String.fromCharCode()
).hexadecimalToBinary()
function first converts the hexadecimal input into a decimal value and then calls the decimalToBinary()
function to convert it into binary. It leverages the parseInt()
method with a base of 16 to convert hex to decimal before converting it to binary.decimalToBinary()
function takes a decimal number as input and converts it to binary by using the toString(2)
method, which converts the number into its binary representation.binaryToDecimal()
function converts a binary input string into its decimal equivalent. It uses parseInt()
with base 2 to interpret the binary string as a decimal number.octalToBinary()
function converts an octal input to binary. It first converts the octal string to decimal using parseInt(octalInput, 8)
, and then calls the decimalToBinary()
function to get the binary result.The binaryToHex()
function handles the conversion of binary data into hexadecimal. It first removes any spaces in the binary input using replace()
, ensuring the binary string is continuous. If the length of the binary string is not a multiple of 4 (the group size for hexadecimal conversion), it pads the string to the left with zeros. Then, it groups the binary string into 4-bit chunks, converts each chunk into a decimal number, and finally converts that decimal value into a hexadecimal character. This results in a string of hexadecimal digits representing the original binary input.
Falls Ihnen Fehler auffallen oder Sie Verbesserungsvorschläge haben, schreiben Sie uns gerne eine Nachricht an L-Studio@gmx.at. Wir freuen uns über Ihr Feedback!