Given a unicode character C (or the first character of a string input), output that character's hex representation. Case does not matter. The output ranges from \u0000 to \u9999.

Test cases

A => 41  (65_10 === 41_16)
ʣ => 2A3 (675_10 === 2A3_16)
Ω => 3A9 (937_10 === 3A9_16)
7 => 37  (55_10 === 37_16)
(null byte) => 0 (0_10 === 0_16)


-50% byte bonus if you output the javascript escape character \uXXXX of the character C, e.g. g => \u0067 and ~ => \u007E

• -1. I think by the standards of this community this is a valid question and I don't see any grounds to close it. However it is especially trivial as evidenced by all the very quick and very short answers. IMO. YMMV. – Digital Trauma Jan 8 '16 at 1:34
• @DigitalTrauma IMO... YMMV... what!? – Seadrus Jan 8 '16 at 1:36
• In My Opinion. Your Mileage May Vary. Knowing the things work around here, this question will end up hitting the HNQ and get lots of votes anyway. – Digital Trauma Jan 8 '16 at 1:38
• @DigitalTrauma +3/-6? – Conor O'Brien Jan 8 '16 at 1:46

# Jolf, 3 bytes

Try it here!

~Ti


Compiles to var i=prompt("i = ");(i).charCodeAt().toString(16);

## Bonus, 13 - 50% = 6.5 bytes

"\\u%"pq~Ti40
"\\u "        prefix
%         interpolate with
~Ti    you know what this is
pq   40  pad with 4 0's

• It's rare to see a -50% bonus score be more than double the non-bonus version. :P – El'endia Starman Jan 8 '16 at 1:32
• @El'endiaStarman Yes, that's a tidbit embarrassing ^^" – Conor O'Brien Jan 8 '16 at 1:33

# Julia, 14 bytes

Interestingly, this is 14 bytes with and without the bonus.

No bonus:

c->hex(Int(c))


Bonus:

c->"\\u"lpad(hex(Int(c)),4,0)


Both are lambda functions that accept Chars and return strings. To call a lambda, assign it to a variable.

We get the code point associated with the Char using Int(), then convert to hexadecimal using hex(). For the bonus, we left pad to 4 characters with zeros and prepend \\u. The backslash needs to be escaped in the string.

• Julia has automatic string concatenation? o-O – Conor O'Brien Jan 8 '16 at 1:35
• @CᴏɴᴏʀO'Bʀɪᴇɴ Here it's actually a combination of two features: Julia uses multiplication to concatenate strings, and in some cases the * can be omitted for multiplication since Julia has coefficient literals (or whatever you want to call it when 2x means 2*x). – Alex A. Jan 8 '16 at 1:38
• ... I remember why I got Julia. Cool language! :D – Conor O'Brien Jan 8 '16 at 1:39

# CJam, 5.5 bytes

"\u%04X"qe%


The code is 11 bytes long and qualifies for the -50% bonus. Try it online in the CJam interpreter.

### How it works

"\u%04X"     e# Push that format string, i.e., a literal "\u", followed by
e%  e# Apply string formatting.


The online interpreter will happily treat the input string as the code point of its sole character. This does not work in the Java interpreter, so it might be a feature or a bug.

## CJam, 520 18 bytes

{iGb{A,6,'Af++=}%}


i converts to integer, G pushes 16, b is base conversion.

... and CJam has no way to use 0-9A-Z instead of base-converting to numbers? That's not annoying at all.

{          }%   map over number-digits
A,             generate the digits 0-9
6,'Af+       generate the "digits" A-F
+      concat
=     array-index into the newly generated array


Thanks to @MartinBüttner for saving 2 bytes!

• {iGb{A,6,'Af++=}%} – Martin Ender Jan 12 '16 at 15:49

# Pyth - 4 bytes

.HCz


Pyth doesn't do unicode for string conversions, instead uses ISO-8859, so cost one more byte.

.H            Hex representation
C            Unicode code point
z           Input string


# JavaScript ES6, 30 54 / 2 = 27 bytes

s=>"\\u"+("000"+s.charCodeAt().toString(16)).slice(-4)


The bonus helped a bit

Try it online at ESFiddle (all browsers work)

• At least we know that this is the absolute hard minimum. I'm sure the bonus will help out here. – Conor O'Brien Jan 8 '16 at 1:41

# Mathematica, 50 - 50% = 25 bytes

"\u"<>IntegerString[First@ToCharacterCode@#,16,4]&


Ignore the error. Mathematica does not recognize the escape code \u, so just escapes the \ and gives a Syntax:stresc message.

# TeaScript, 5 bytes

xcT16


I'm very sure I have a unicode shortcut for 16

Try it online

• Isn't m=16 from the docs? – ev3commander Jan 9 '16 at 1:00
• @BlockCoder1392 yeah but I'd still have to replace 16 with (m which isn't any shorter – Downgoat Jan 9 '16 at 1:01

## Python 2, 27/2 = 13.5 bytes

lambda x:r'\u%04X'%(ord(x))


No online link because apparently ideone's Python 2 version doesn't support Unicode string literals.

# Japt, 5 bytes

Uc sG


Very simple. Try it online!

### How it works

Uc sG  // Implicit: U = input, G = 16
Uc     // Take the char code of U.
sG  // Turn it into a base-16 string.
// Implicit: output last expression


### Bonus version, 20 bytes * 0.5 = 10

"\\u{'0³+Uc sG)t0-4


Not as simple. Try it online!

### How it works

          // Implicit: U = input, G = 16
"\\u{     // Take the string "\u", and add:
'0³+     //  Take 3 "0"s, plus
Uc sG)   //  the hex char code of the input.
t0-4     //  Take the last 4 chars.
// Implicit: output last expression


# 𝔼𝕊𝕄𝕚𝕟, 3 chars / 8 bytes

ï⒞ⓧ


Try it here (Firefox only).

Superbly simple. Convert to charcode, then to hex.