Big or Little Endian

Write a program or function that outputs an L if run on a little endian architecture or a B if run on a big endian architecture. Lower case output l or b is also acceptable.

There is no input.

Scoring is code golf, so the code with the fewest bytes wins.

Edit: As per the comments below, I am clarifying that the entry must be able to run on either architecture.

I believe that there is only one answer that this affects, and that answer has clearly indicated that this is the case.

• The memory of the box. I'm not sure what you mean – Liam Jul 27 '16 at 23:38
• I think this is an interesting challenge (and it's way out of the norm) but it's going to be extremely hard to test it. Especially since most of the code will end up being extremely platform specific. – DJMcMayhem Jul 27 '16 at 23:41
• Yeah I think it'll be interesting because hopefully it's something that esolangs and golfing languages have a harder time with than 'normal' languages. I have a feeling that they won't be that hard to verify. Worst case they should be verifiable by hand – Liam Jul 27 '16 at 23:43
• I guess an answer based on a specific machine code is forbidden? Otherwise B0 4C C3, which is mov al, 'L' / ret or unsigned char f(){ return 'L'; }, would be a valid x86 answer. – Margaret Bloom Jul 28 '16 at 7:28
• Bravo! for a code golf challenge in which general-purpose programming languages can be competitive. – PellMell Jul 29 '16 at 21:16

Dyalog APL, 281916 15 bytes

Both solutions below require ⎕IO←0, which is default on many systems.

In cooperation with my CTO:

'BL'⊃⍨⊃11⎕DR'⊢'


11⎕DR'⊢' interpret the character as 1 bit Boolean
{0,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0} on big-endian systems
{1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0} on little-endian systems

⊃ pick the first number, i.e. 0 on big endian systems, and 1 on little-endian systems

'BL'⊃⍨ use that to pick from the string

This one is a bit interesting, as it requires storing in the "Classic" character set to be only 15 bytes, but must be executed in the "Unicode" interpreter to get a two byte representation. However, this is not a contradiction as the Unicode interpreter can load Classic workspaces.

Old solution:

'LB'⊃⍨'E'⎕FPROPS⎕D⎕FCREATE 0


⎕D⎕FCREATE 0 create an APL component file with the name 0123456789
'E'⎕FPROPS query endian-ness (0=little, 1=big)
'LB'⊃⍨ pick from the string

GNU Utils, 35 bytes

lscpu|grep -o ':.*n'|grep -Eo 'L|B'


Tested on Linux kali 4.6.0-kali1-amd64 #1 SMP Debian 4.6.4-1kali1 (2016-07-21) x86_64 GNU/Linux, but I'm pretty sure the output should be fairly standard on most GNU/Linux distros.

Kotlin, 42 bytes

{(""+java.nio.ByteOrder.nativeOrder())[0]}


Pretty straightforward. Uses "native" Java API. This is a lambda of () -> Char type.

String templates don't help much, unfortunately (still 42 bytes):

{"${java.nio.ByteOrder.nativeOrder()}"[0]}  Function approach (48 bytes): fun e()=(""+java.nio.ByteOrder.nativeOrder())[0]  Nim, 21 20 bytes ($cpuEndian)[0].echo


Takes the cpuEndian builtin (either littleEndian or bigEndian depending on the target CPU), stringifies it with $, takes its 0th character (l or b depending on the target CPU), and uses Nim's uniform function call syntax to echo the result. Lua, 31 bytes print(("H"):pack(19522):sub(2))  Lua 5.3 is required. VBA, 151 Bytes Type x q As Long End Type Type z w As Integer End Type Sub q() Dim i As x, y As z y.w=1 LSet i=y Debug.? IIf(i.q=1,"L","B") End Sub  Tcl, 46 bytes puts [string index$tcl_platform(byteOrder) 0]


(Nothing fancy. Just in case someone wants to know how to do it in Tcl.)

C# 50 49 bytes

Works, but has to be marked as unsafe

char i(){var a=0x0001;return*(byte*)&a>0?'L':'B';}


Updated:

unsafe char i(){int a=1;return"BL"[*(byte*)&a];}

• You can use a classic trick since this is really producing 0 or 1, and index into a string to get the character "BL"[...]. Given it has to be run in an unsafe context, it should probably start with "unsafe char", and the compiler flag might need to be counted (I think it would be 1 byte, I can't remember the rules on that)... I should think you don't need any of the "0x000" stuff, "int a=1" ought to do fine. – VisualMelon Jul 31 '16 at 12:41
• @VisualMelon you're right, unsafe char i(){int a=1;return"BL"[*(byte*)&a];} is ok? – Daniel Norris Aug 2 '16 at 16:55
• Yeah, that looks good (well remembered removing the space after the return, easy to miss that one) – VisualMelon Aug 2 '16 at 17:28