g | x | w | all
Bytes Lang Time Link
046AWK250806T151738Zxrs
331Bespoke250730T054327ZJosiah W
018APLNARS250308T162519ZRosario
062Tcl170525T183719Zsergiol
001Thunno 2230622T173908ZThe Thon
019><> Fish230314T131231Zemirps
022Julia 1.0230328T201106ZAshlin H
015Stax230328T151259Zemirps
050Lua230313T192451Zemirps
029q230327T184447Zeohara-i
010Japt190912T085924ZShaggy
004Vyxal230312T120733ZThe Thon
007Jelly201225T223314Zcaird co
067Forth gforth190912T145232Zreffu
048Commodore BASIC C64/128/TheC64190912T115054ZShaun Be
062Haskell190912T122505Zflawr
013MathGolf190912T120919ZKevin Cr
00905AB1E legacy190912T101338ZKevin Cr
010Brachylog190912T041142ZUnrelate
026q/kdb+170817T152539Zmkst
027C++ gcc170817T154550ZKarl Nap
033Excel170817T145203ZWernisch
033DASH161029T041138ZMama Fun
058Racket161029T022618Zrnso
010ASM160816T233747Z6a75616e
030Java160816T094531ZShaun Wi
445Brainfuck160818T061911ZATaco
041Mathematica 41 Bytes160816T084959ZDavidC
019Befunge 93160816T100535ZDaniel
041JavaScript160817T140323Zuser2428
044q160817T105739Zskeevey
060Javascript160816T130144ZDylan Me
061Java160817T051148ZAJNeufel
072SQF160817T003356ZΟurous
050Python 3160815T232430ZDestruct
010MATL160816T215445Zbeaker
051Pure Bash160816T010020ZDigital
031Ruby160815T220656ZValue In
019Befunge98*160816T153141Ztngreene
062R160816T123232ZForgotte
014Dyalog APL160816T133628ZAdá
042PowerShell v2+160816T125919ZAdmBorkB
073R160816T111415ZMamie
040PHP160816T065701ZJeroen
053Gema160816T103443Zmanatwor
007Actually160816T014506Zuser4594
043Python 3160816T044845Zcdlane
013Pyth160816T063232ZLeaky Nu
025Perl 6160816T024524ZBrad Gil
032C#160816T021736Zmilk
032Cheddar160815T231703ZDowngoat
055C160816T003558Zorlp
038Python 2160816T002645ZDennis
044Python 2160815T234444ZAdnan
030Fourier160815T215359ZBeta Dec
049JavaScript ES6160815T233911ZNeil
026Erlang160815T220555Za spaghe
054Haskell160815T231431Znimi
0082sable160815T220341ZAdnan
075R160815T225245Zuser5957
061Python 2160815T224040ZKarl Nap

AWK, 46 bytes

@load"ordchr"
$0=/[A-Z]/?ord($0)-64:chr($0+64)

Attempt This Online!

Bespoke, 331 bytes

find A-B-C given an integer/convert ABC to number
I read it in ASCII
assuming an integer is put in now,my strategy builds digits
a decimal has ten as a number denoting values in places
add to a particular alphabet character
integers from ASCII:we do some division formula
finding out in a mod by thirty-twos whatever size counts it

Bespoke has a command to take in numerical input, but it errors out if the input given is not a number. So I was left in the unenviable position of writing a routine to convert string input to a number. Just about the best thing I can say about it is that it works.

APL(NARS), 18 chars

{''≡0↑⍵:⎕A⍳⍵⋄⍵⊃⎕A}

It suppose input only one letter in the range A..Z or a numeric range 1..26. In my apl file it is said that ''≡0↑⍵ return 1 if in there is one string or one letter else return 0.

Test:

  {''≡0↑⍵:⎕A⍳⍵⋄⍵⊃⎕A}1
A
  {''≡0↑⍵:⎕A⍳⍵⋄⍵⊃⎕A}'B'
2
  {''≡0↑⍵:⎕A⍳⍵⋄⍵⊃⎕A}'Z'
26
  {''≡0↑⍵:⎕A⍳⍵⋄⍵⊃⎕A}26
Z

Tcl, 62 bytes

Not a champion by any measure, but I had to do it.

puts [expr {[string is di $a]?[format %c $a+64]:[scan $a %c]}]

Try it online!

Thunno 2, 1 byte

Ä

Attempt This Online!

Overloaded built-in that works on both numbers (1 -> A, 2 -> B, ...) and letters (A -> 1, B -> 2, ...).

><> (Fish), 27 24 21 19 bytes

<o+v?)0-}:"@":
n-$<

Try it with a number test case

Try it with a letter test case

Takes input on the stack, which is a default input method for stack-based languages, and outputs with error.

Julia 1.0, 22 bytes

~a=a-'@'
~n::Int=n+'@'

Try it online!

This solution involves a single function with 2 methods.

Stax, 15 bytes

Ö└╝╨→ε/óo↕[▄╢▐W

Run and debug it

This unpacks to the following 18 bytes:

cc%!{64+z+}{E64-}?

Run and debug it

Lua, 76 53 50 bytes

x=...y=x:byte()print(64<y and y-64or x.char(x+64))

Try it online!

Explanation

x=... -- unpack command line arguments into x
y=x:byte()
print(
64<y -- if the first byte of the string > 64:
and y-64 -- print the first byte-64
or x.char(x+64) -- else, print chr(x+64)
)

q, 29 bytes

{@[1+.Q.A?;x;{.Q.A y-1}[;x]]}

Find the index at which our letter occurs in the built-in list of uppercase letters

If it errors, index into the same list with the input instead

Adding and taking away ones as q indexing starts at 0, not 1

Japt, 11 10 bytes

¤?UdI:InUc

Try it

¤?UdI:InUc     :Implicit input of integer or string U
¤              :Convert to binary string if integer (always truthy)
¤              :Slice off first 2 character if string (always falsey)
 ?             :If truthy
  Ud           :  Get character at codepoint U
    I          :  After first adding 64
     :         :Else
      In       :  Subtract 64 from
        Uc     :  Codepoint of U

Vyxal, 12 4 bytes

øAɾt

Try it Online!

Explanation

Of course there's a built-in

øAɾt # Implicit input
øA   # Letter to number or number to letter
  ɾ  # Range or uppercase (overloaded)
   t # Last item

Old:

‹kA:?c[?ḟ›|i  # Implicit input
‹             # Decrement (no effect on strings)
 kA:          # Push uppercase alphabet and duplicate
    ?c        # Is the input alphabetic?
      [       # If it is:
       ?ḟ     #  Find the 0-based index of the input in the alphabet
         ›    #  And increment it to make it 1-based
          |   # Otherwise:
           i  #  Index input-1 into the alphabet

Jelly, 7 bytes

i@ịe?ØA

Try it online!

How it works

i@ịe?ØA - Main link. Takes an input A on the left
     ØA - Set the right argument to "ABC...XYZ"
    ?   - If statement:
   e    -   Condition: left in right; is A in the alphabet?
i@      -   If so: return the 1-index of A in the alphabet
  ị     -   Else: yield the A'th element of the alphabet

Forth (gforth), 67 bytes

: f 2dup s>number? if d>s 64 + emit else 2drop d>s c@ 64 - . then ;

Try it online!

Input is passed as a string to the function

Code Explanation

: f             \ start a new word definition
  2dup          \ make a copy of the input string
  s>number?     \ attempt to convert to a number in base 10
  if            \ check if successful
    d>s         \ drop a number (don't need double-precision)
    64 + emit   \ add to 64 and output the ascii letter at that value
  else          \ if not successful (input was a letter)
    2drop d>s   \ get rid of garbage number conversion result and string-length
    c@ 64 - .   \ get ascii value of char, subtract 64 and output 
  then          \ end the if block
;               \ end the word definition

Commodore BASIC (C64/128/TheC64, VIC-20, PET) - 90 48 (tokenized) bytes

 0inputa$:ifval(a$)>0then?chr$(64+val(a$)):end
 1?asc(a$)-64

Explanation and screen shot later.

Haskell, 63 62 bytes

This uses the rule that wrapping the output in an optional type is allowed. We just use the standard lookup function to search in a list of tuples that define the input/output relationship.

(`lookup`zip(c++n)(n++c))
c=pure<$>['A'..'Z']
n=show<$>[1..26]

Try it online!

MathGolf, 13 bytes

▄l!╧¿É$♦-É♦+$

Try it online.

Explanation:

 l         # Push the input as string
  !        # Convert it to lowercase
    ¿      # If
▄          #    the lowercase alphabet
   ╧       #                           contains this value:
     É     #  Execute the following three operations:
      $    #   Convert the (implicit) input to its unicode value
       ♦-  #   Subtract 64
           # (Implicit else:)
     É     #  Execute the following three operations:
      ♦+   #   Add 64 
        $  #   And convert it to the character with this unicode value
           # (after which the entire stack joined together is output implicitly)

05AB1E (legacy), 9 bytes

di.bëÇ64-

Try it online or verify all test cases.

Also works in the new version of 05AB1E instead of the legacy, but the Ç wraps in a list: Try it online or verify all test cases.

Explanation:

di      # Legacy 05AB1E version: If the (implicit) input is an integer:
        # New 05AB1E version: If the (implicit) input is a positive (>= 0) integer:
  .b    #  Builtin to convert the integer to its 1-based uppercase alphabetic letter
 ë      # Else:
  Ç     #  Get the codepoint of the uppercase letter
   64-  #  And subtract 64 to convert it to its 1-based index
        # (after which the result is output implicitly)

Brachylog, 10 bytes

;.L∧Ṇi₁pL∧

Try it online!

The core of this is only 4 bytes, but the I/O for that version is a bit less than sane.

q/kdb+, 28 26 bytes

Solution:

{((?;@) -7=(@)x)[`,.Q.A]x}

Examples:

q){((?;@) -7=(@)x)[`,.Q.A]x}1
"A"
q){((?;@) -7=(@)x)[`,.Q.A]x}2
"B"
q){((?;@) -7=(@)x)[`,.Q.A]x}26
"Z"
q){((?;@) -7=(@)x)[`,.Q.A]x}"A"
1
q){((?;@) -7=(@)x)[`,.Q.A]x}"B"
2
q){((?;@) -7=(@)x)[`,.Q.A]x}"Z"
26

Explanation:

Check the type of the input, if it's a long (-7h) then use the apply @ operator to index into the alphabet .Q.A, otherwise use ? to lookup the input in the alphabet. Note that we add null to the start of the alphabet to fake the 1-indexing:

{((?;@) -7h=type x)[`,.Q.A;x]} / ungolfed solution
{                            } / lambda function
                   [      ; ]  / apply a function to this
                    `,.Q.A     / join ` (null) to the string "ABC...XYZ"
                           x   / implicit input (e.g. "A" or 13)
 (                )            / do all this together
        -7h=type x             / is the type of parameter x a long (-7)
  (?;@)                        / ? (lookup) if true, @ (index) if false

Notes:

C++ (gcc), 27 bytes

As unnamed generic lambda, accepting char or int and returning via reference parameter (input=output)

[](auto&r){r+=r<64?64:-64;}

Try it online!

Excel, 33 bytes

=IFERROR(CHAR(A1+64),CODE(A1)-64)

DASH, 33 bytes

@[="num"type#0?fc +64#0?-(tc#0)64

Woo-hoo, first PPCG answer in my new functional programming language!

Installation and other info is all on the Github.

Usage

(@[="num"type#0?fc +64#0?-(tc#0)64])"A"  #. strings
(@[="num"type#0?fc +64#0?-(tc#0)64])26   #. numbers

Explanation

@                      #. lambda
  [                    #. start of conditional block
    = "num" (type #0)  #. check if argument is a number
      ? fc (+ 64 #0)   #. if so, add 64 to argument and convert from charcode
      ? - (tc #0) 64   #. otherwise, convert argument to charcode and subtract 64
                       #. we can actually leave off the closing bracket for now

Racket 58 bytes

(if(char? i)(-(char->integer i)64)(integer->char(+ 64 i)))

Ungolfed:

(define (f i)
  (if (char? i)
      (-(char->integer i) 64)
      (integer->char (+ 64 i))))

Testing:

(f 1)
(f 3)
(f #\A)
(f #\D)

Output:

#\A
#\C
1
4

ASM: 10 bytes

3C 40 77 04 2C 40 EB 02 04 40

Explanation: This is the assembled representation of a program that does exactly what is asked. It is not fully functional, because it needs some directives, but if it is added to the code segment of an assembly program it should work. It receives the input in the AL register, and if its a letter it subtracts 40h from the ASCII code value, leaving just the number(i.e B=42h, 42h-40h=2h). If the input is a number it does the opposite procedure by adding 40h. It leaves the result in the AL register. Below is the assembly source code

cmp al,40h
ja letter_to_number
sub al,40h
jmp continue
letter_to_number: add ax,40h
continue:

Also, if you convert all the other answers to machine code, I am positive that mine would be the smallest.

Java, 104 98 97 83 54 53 51 50 30 bytes

x->(x^=64)>64?(char)x+"":x+"";

Test Program:

IntFunction<String> f = x -> (x ^= 64) > 64 ? (char) x + "" : x + "";
out.println(f.apply('A')); // 1
out.println(f.apply('Z')); // 26
out.println((f.apply(1))); // A
out.println((f.apply(26))); //Z

Brainfuck, 445 Characters

More a proof of concept than a golfed code. Requires Unsigned, Non-wrapping Brainfuck.

,[>+>+<<-]>[<+>-]>>++[->++++++<]>[-<<<+++++>>>]<<<<[->-<]>[,<++++[->------------<]++++[->>------------<<][-<<++++++++++>>]>[-<+>]>[-<<++++++++++>>]>++[->++++++<]>+[-<+++++>]<-[-<<<+>>>]<<<.>]>[[-<+<+>>]>++[->++++++<]>+[-<+++++>]<-[-<<->>]<<[->+>+<<]>>>++++++++++<+[>[->+>+<<]>[-<<-[>]>>>[<[-<->]<[>]>>[[-]>>+<]>-<]<<]>>>+<<[-<<+>>]<<<]>>>>>[-<<<<<+>>>>>]<<<<<-[->+>+<<]>[-<++++++++++>]<[-<->]++++[-<++++++++++++>]++++[->>++++++++++++<<]>>.<<<.>]

With Comments

,[>+>+<<-] Firstly Duplicate it across two buffers
>[<+>-] Move the second buffer back to the first buffer
>>++[->++++++<]>[-<<<+++++>>>] Establish 60 in the second buffer
<<<<
Compare Buffers 1 and 2
[->-<]
>
[ If there's still data in buffer 2
, Write the value in the units column to buffer two
<
++++
[->------------<] Subtract 12 from the units buffer
++++
[->>------------<<] Subtract 12 from the tens buffer
[-<<++++++++++>>] Multiply buffer three by ten into buffer 1
>
[-<+>] Add the units
>
[-<<++++++++++>>] Add the tens
>++ Add 65 to the buffer
[->++++++<]>+
[-<+++++>]
<- Actually we need 64 because A is 1
[-<<<+>>>] Add 64 to the first buffer
<<<
. Print the new letter
> Move to blank buffer
]
>
[ Otherwise we're a letter
[-<+<+>>] Copy it back over the first two buffers
>++ Write 64 to the buffer
[->++++++<]>+
[-<+++++>]
<-
[-<<->>] Subtract 64 from the letter
<<[->+>+<<]
>>>++++++++++< Copy pasted Division step x = current buffer y = 10 rest of the buffers are conveniently blank

+
[>[->+>+<<]>[-<<-[>]>>>[<[-<->]<[>]>>[[-]>>+<]>-<]<<]>>>+<<[-<<+>>]<<<]>>>>>[-<<<<<+>>>>>]<<<<<
-
[->+>+<<]
>[-<++++++++++>]
<[-<->]
++++
[-<++++++++++++>]
++++
[->>++++++++++++<<]
>>.<<<.>
] 

Mathematica 54 41 Bytes

With an absolutely clever suggestion from LegionMammal978 that saves 13 bytes.

If[#>0,FromLetterNumber,,LetterNumber]@#&

If[#>0,FromLetterNumber,,LetterNumber] serves the sole purpose of deciding whether to apply FromLetterNumber or LetterNumber to the input.

#>0 will be satisfied if the input, #, is a number, in which case FromLetterNumberwill be selected.

However #>0 will be neither true nor false if # is a letter, and LetterNumber will be selected instead.


If[#>0,FromLetterNumber,,LetterNumber]@#&["d"]

4


If[#>0,FromLetterNumber,,LetterNumber]@#&[4]

d


In Mathematica, FromLetterNumber and LetterNumber will also work with other alphabets. This requires only a few more bytes.

If[# > 0, FromLetterNumber, , LetterNumber][#, #2] &[4, "Greek"]
If[# > 0, FromLetterNumber, , LetterNumber][#, #2] &[4, "Russian"]
If[# > 0, FromLetterNumber, , LetterNumber][#, #2] &[4, "Romanian"]

δ
г
b

If[# > 0, FromLetterNumber, , LetterNumber][#, #2] &[δ, "Greek"]
If[# > 0, FromLetterNumber, , LetterNumber][#, #2] &[г, "Russian"]
If[# > 0, FromLetterNumber, , LetterNumber][#, #2] &[b, "Romanian"]

4
4
4

Befunge 93, 144 90 66 54 36 19 bytes

Not 100% sure if this is allowed, but if you are allowed to type A as 65, B as 66, etc., then (for [my] convenience's sake):

&:"@"`"@"\#. #-_+,@

Otherwise, at 36 bytes:

~:0\"A"-`#v_88*-.@
**~28*++,@>68*-52

(Thanks to tngreene for the suggestions!)

~:0\567+*-`#v_88*-.>$28*+,@
52**\28*++,@>~:0`!#^_\68*-

(Thanks to Sp3000 for saving 12 bytes by rearranging!)

~:0\567+*-`#v_88*-.>$82*+,@
            >~:0`!#^_\68*-52**\28*++,@


v                   >$28*+,@
             >~:0`!#^_\68*-52**\28*++,@
>~:0\567+*-`#^_88*-.@


v                    >$28*+,@
~           >11g~:0`!|
1                    >\68*-52**\28*++,@
1
p           
>011g567+*-`|
            >11g88*-.@

Ungolfed:

v                       >$ 28* + , @
                 >~:0 `!|
                        >\ 68* - 52* * \ 28* + + , @
>~:0\ 5 67+ * - `|
                 >88* - . @

This is my first working Befunge program ever, and I feel the need to golf this further. Any help would be greatly appreciated.

You can test Befunge code here.

JavaScript, 41 bytes

x=>-x?(9+x).toString(36):parseInt(x,36)-9

q, 44 bytes

Reads from stdin

{$[0N~i:"J"$x;1+.Q.A?x 0;.Q.A i-1]}[read0 0]

Javascript 86 77 66 60 bytes

i=>typeof i<'s'?String.fromCharCode(i+64):i.charCodeAt(0)-64

Java, 61 bytes

int f(char c){return c^64;}char f(int i){return(char)(i^64);}

Ungolf'd:

int f(char c) {
    return c^64;
}

char f(int i) {
    return (char) (i^64);
}

Calling f('A') invokes the first function, retuning an int 1; calling f(1) invokes the second function, returning the char "A".

SQF, 72 bytes

Using the function-as-a-file format:

i=_this;if((str i)==i)then{toString[i+64]}else{((toArray i)select 0)-64}

Call as: ARG call NAME_OF_COMPILED_FUNCTION

Python 3, 49 48 53 50 bytes

Somehow I got the byte count wrong ;_; thanks dahuglenny

isalpha is shorter than isnumeric

lambda x:x.isalpha()and ord(x)-64or chr(int(x)+64)

takes input as string, which could be a letter or number

MATL, 10 bytes

6WZ~t42>?c

Explanation:

6W              % 2**6 = 64, but golfier looking
  Z~            % bit-wise XOR with input
    t42>?       % if result is greater than 42
         c      % convert it to a character 
                % else, don't

Try it online! with numeric inputs.
Try it online! with alphabetic inputs.

Pure Bash, 51

Most of the rest of the answers use some sort of conditional. This one dispenses with conditionals entirely, and instead treats the input as a base-36 number which indexes into an appropriately constructed bash-brace-expansion array:

a=(_ {A..I} {1..26} {J..Z} {A..Z})
echo ${a[36#$1]}

Ideone.

Ruby, 47 39 + n flag = 40 bytes 33 34 31 bytes

Anonymous function. Uses an exception handling trick like in @KarlNapf's Python solution.

-3 bytes from @manatwork

Try it online

->i{(64+i).chr rescue i.ord-64}

Original full program version with the n flag for 40 bytes and reads from STDIN:

puts$_!~/\d/?$_.ord-64:(64+$_.to_i).chr

Befunge-98*, 19 bytes

&:39*\`'@\j;+,@;-.@

Because the question said you'll receive a 1-26 or an A-Z I assumed this meant the number 26 or the character A-Z. Most interprets struggle with entering alt-codes, so it is easier to use & and enter values like 26 for 26 or 90 for 'Z', as opposed to ~.

Pseudo-code

int c = get stdin
push the value of 27
bool is_number =  27 > c
push the value of `@` (64)
if is_number == 1
   jump to adding 64 to c //putting it the ASCII range
   print as ASCII
   end
else
   jump to subtracting 64 from c //putting it in the numerical range
   print as number
   end

Test it out (on Windows) here!

*This is technically Unefunge-98 because it only uses 1 dimension, but that name might be unfamiliar.

R, 62 Bytes

f=function(x)ifelse(is.finite(x),LETTERS[x],which(LETTERS==x))

Takes the input x and checks if it is finite, which is one byte shorter than checking if it is numeric and equivalent in this case. If yes, output the letter, if no, output the position in the alphabet equal to the character input.

Dyalog APL, 14 bytes

{0::⎕A⍳⍵
⍵⊃⎕A}

0:: if any error happens:
⎕A⍳⍵ return the index of the argument in the alphabet

⍵⊃⎕A use the argument to pick an element from the alphabet (errors if the argument is character)

TryAPL online!

PowerShell v2+, 42 bytes

param($n)([char](64+$n),(+$n-64))[$n-ge65]

Takes input $n (as an integer or an explicit char) and uses a pseudo-ternary to choose between two elements of an array. The conditional is $n-ge65 (i.e., is the input ASCII A or greater). If so, we simply cast the input as an int and subtract 64. Otherwise, we add 64 to the input integer, and cast it as a [char]. In either case, the result is left on the pipeline and printing is implicit.

Examples

PS C:\Tools\Scripts\golfing> ([char[]](65..90)|%{.\alphabet-to-number.ps1 $_})-join','
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26

PS C:\Tools\Scripts\golfing> (1..26|%{.\alphabet-to-number.ps1 $_})-join','
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z

R, 73 bytes

f=function(x){L=LETTERS;if(is.numeric(x)){i=L[(x)]}else{i=which(L==x)};i}

PHP, 49 41 40 bytes

<?=+($i=$argv[1])?chr($i+64):ord($i)-64;

I do not think there is a good alternative to is_numeric right?

This is executed from command line ($argv[1] is the first variable given)

Thanks to:

@insertusernamehere: Golfed 8 bytes. Replacing is_numeric($i=$argv[1]) with 0<($i=$argv[1]).This works because (int)"randomLetter" == 0.

@manatwork: Reduced with 1 byte. Replace 0< with +. What happens in this case is that the + signal will cast the "Z" (or whatever letter) to an 0. This will result in false. Therefor any letter is always false and a number is always true.

Gema, 53 characters

<K>=@sub{@char-int{$0};64}
<D>=@int-char{@add{$0;64}}

Sample run:

bash-4.3$ gema '<K>=@sub{@char-int{$0};64};<D>=@int-char{@add{$0;64}}' <<< 'M'
13

bash-4.3$ gema '<K>=@sub{@char-int{$0};64};<D>=@int-char{@add{$0;64}}' <<< '13'
M

Actually, 7 bytes

ú' +ûEí

Try it online!

Explanation:

ú' +ûEí
ú' +     lowercase English alphabet, prepend space
    û    uppercase
     E   element (pushes the nth letter if input is an integer, leaves stack alone otherwise)
      í  index (pushes index of input if input is a string, leaves stack alone otherwise)

If lowercase is acceptable, this is 6 bytes:

ú' +Eí

Try it online!

Python 3, 43 bytes

lambda x:x!=str(x)and chr(64|x)or ord(x)^64

The interesting thing about this solution is that it incorporates all the senses of OR, bitwise OR |, logical OR or, bitwise XOR ^ and logical XOR != ...

Pyth, 13 bytes

.xC+64sQhxr1G

Test suite.

Perl 6, 25 bytes

{+$_??chr $_+64!!.ord-64}

Explanation:

# bare block lambda with implicit parameter of 「$_」
{
    +$_         # is the input numeric
  ??
    chr $_ + 64 # if it is add 64 and get the character
  !!
    $_.ord - 64 # otherwise get the ordinal and subtract 64
}

Example:

say ('A'..'Z').map: {+$_??chr $_+64!!.ord-64}
# (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26)

say (1..26).map: {+$_??chr $_+64!!.ord-64}
# (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)

C#, 32 bytes

n=>(n^=64)>26?(object)(char)n:n;

Casts to Func<int, object>.

Input: char implicitely converts to int so can be called with int (1-26) or char ('A'-Z').

Output: Either a char or int.

Cheddar, 34 32 bytes

Saved 2 bytes thanks to @LeakyNun

n->"%s"%n==n?n.ord()-64:@"(n+64)

I wish there was shorter way to check if string or number.

Try it online! or Test Suite

Explanation

n ->                // func with arg `n`
    "%s"%n==n ?     // if n is string... (see below)
       n.ord() - 64  // return code point - 64
    :               // else...
    @"(n+64)         // chr(n+64)

"%s"%n==n checks if it is a string in a simple way. "%s" is a string format, I can format with % e.g. "a %s c" % "b" is equal to "a b c". %s specifies it is a string, if a digit is passed it'll remain as %s.

C, 55 bytes

i;f(char*s){i=atol(s);printf(i?"%c":"%d",64^(i?i:*s));}

Python 2, 38 bytes

lambda x:x>''and 64^ord(x)or chr(64^x)

Test it on Ideone.

Python 2, 45 44 bytes

Code:

lambda x:chr(x+64)if`x`[0]>"("else ord(x)-64

Fourier, 30 bytes

I~F<64{1}{F+64a}F>64{1}{F-64o}

Try it online!

JavaScript (ES6), 49 bytes

s=>s>0?String.fromCharCode(s|64):parseInt(s,36)-9

Accepts integers in either number or string format, always return integers as a number. 42 bytes if I can return lower case and don't need to handle integers in string format:

s=>s>0?(s+9).toString(36):parseInt(s,36)-9

Erlang, 26 bytes

f([X])->X-64;f(X)->[X+64].

One of the few times where Erlang's string behavior is useful.

Haskell, 54 bytes

f s|s<"A"=[['@'..]!!read s]|1<2=show$fromEnum(s!!0)-64

Usage example: map f ["1","26","A","Z"] -> ["A","Z","1","26"].

Haskell's strict type system is a real pain here. Additionally all the short char <-> int functions like chr and ord need an import, so I have to do it by hand. For the letter -> int case, for example I need to convert String -> Char (via !!0) -> Integer (via fromEnum) -> String (via show).

2sable, 9 8 bytes

Code:

.bAu¹kr,

Explanation:

.b        # Convert 1 -> A, 2 -> B, etc.
  A       # Push the alphabet.
   u      # Convert it to uppercase.
    ¹k    # Find the index of the letter in the alphabet.
      r   # Reverse the stack.
       ,  # Pop and print with a newline.

Uses the CP-1252 encoding. Try it online!.

R, 75 bytes

f=function(l,a=which(LETTERS==l))ifelse(length(a),a,LETTERS[as.numeric(l)])

This function technically has two inputs. But the second one is merely there because by setting a through a default, I can get rid of 2 bytes. Give the function a quoted letter or number, or just a number, and it will return the opposite.

Explanation: a tests if it is a letter and which one it is. If it isn't it pulls the relevant letter.

Python 2, 61 bytes

i=raw_input()
try:o=chr(int(i)+64)
except:o=ord(i)-64
print o

Yes I could switch to Python 3 for input