Skip to content

Instantly share code, notes, and snippets.

@sweeneyapps
Created July 20, 2021 20:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sweeneyapps/5ec2ace9b0551b31f784a0e6c065b057 to your computer and use it in GitHub Desktop.
Save sweeneyapps/5ec2ace9b0551b31f784a0e6c065b057 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ASCII to Binary</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
<style>
body {
background-color: black;
color: #fff;
letter-spacing: 0.5px;
font-family: monospace;
}
input {
width: 100%;
}
</style>
</head>
<body>
<div id="app">
<h1>ASCII-Binary Converter</h1>
<input v-model="message" type="text"> <button v-on:click="clear">Clear</button>
<p> {{ binary }} </p>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
message: 'I am awesome!'
},
computed: {
binary: function () {
return this.message.split('').map(function (char) {
return char.charCodeAt(0).toString(2).padStart(8, '0')
}).join(' ')
}
},
methods: {
clear: function () {
this.message = ''
}
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment