asciify-hexify.js

/** * ASCIIfy–Hexify bookmarklet * v.92 * * Authors: Lucas Larson, 2017 * Steve Kangas, 1998 * * Description: This is the JavaScript behind a bookmarklet to obtain the * ASCII₁₀ value and hexadecimal value of any single character. * * Installation: See bottom * * Use: Tap the bookmarklet, enter any single character – lowercase n, * for example – and the bookmarklet returns n’s ASCII and * hexadecimal values with the following output: * The ASCII number for “n” is 110, * and its hexadecimal value is 6E. * * * Credit to For * David Rubin Confidence * Steve Kangas Character to ASCII bookmarklet http://bookmarklets.com/tools/design * Travis Decker “hexify” instead of “hexafy” * John Tantalo The bookmarklet-as-a-gist idea https://gist.github.com/tantalor/202523 * Chris Zarate Bookmarkleter (with IIFE-fier!) https://chriszarate.github.io/bookmarkleter * Joey Twiddle Easing bookmarklet development https://stackoverflow.com/a/4488511 */ // the variable below “‘window’ is not defined” unless the // browser environment is specified with “/* eslint-env browser */” // via Carles Alcolea https://stackoverflow.com/a/55198538 /* eslint-env browser */ // Opt out of JavaScript’s Sloppy Mode 'use strict' // Anonymize the function void (function () { // “Kangas” ends in s but isn’t plural, so we’ll add an apostrophe as well as // the letter s for the possessive // Steve Kangas’s “p5VgU2z1” becomes “asciify” var asciify = window.prompt('Enter a character:', '') // avoid NaN output by executing only if asciify has a value if (asciify) { // forbid entries of more than one character if (asciify.length > 1) { window.alert('Please enter only one character.') } else { window.alert('The ASCII number for “' + asciify + '” is ' + asciify.charCodeAt(0) + ',\nand its hexadecimal value is ' + // .toString(16) via Matt Dunlap https://stackoverflow.com/a/57805 // .toUpperCase() via Fabio Ferrari https://stackoverflow.com/a/6680530 asciify.charCodeAt(0).toString(16).toUpperCase() + '.') } } // Installing bookmarklets is famously tricky (see // https://mreidsma.github.io/bookmarklets/installing ), but when you’re ready, // the URI to enter into the bookmark’s address field is everything on the line // between the /* and the */ }()) /* javascript:'use%20strict';void%20function(){var%20asciify=window.prompt('Enter%20a%20character:','');asciify%26%26(asciify.length%3E1%3Fwindow.alert('Please%20enter%20only%20one%20character.'):window.alert('The%20ASCII%20number%20for%20\u201C'+asciify+'\u201D%20is%20'+asciify.charCodeAt(0)+',\nand%20its%20hexadecimal%20value%20is%20'+asciify.charCodeAt(0).toString(16).toUpperCase()+'.'))}(); */
ASCIIfy–Hexify: A bookmarklet to find a character’s ASCII and hexadecimal value

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.