# Only Even Bytes

## The scenario

Lately you have been noticing some strange behavior with your favorite text editor. At first it seemed that it was ignoring random characters in your code when writing to disk. After a while you noticed a pattern; characters with odd ASCII values were being ignored. Under further inspection you discovered that you can only write to files properly if every eighth bit is zero. Now you need to know if your valuable files have been affected by this strange bug.

You must write a complete program that determines if a file contains any odd bytes (demonstrating it is uncorrupted). But because of your text editor you cannot write any odd bytes in your source code. You may assume any pre-existing encoding for input, however you must still check every individual byte, not just characters.

### Input

Your program will take the contents of or the path to a file from either stdin or command line.

### Output

Your program will output to stdout either a truthy value if the given file contains an odd byte or a falsy if every eighth bit is zero.

## Criteria

This is code golf, shortest program that completes the task wins. To be a valid submission every eighth bit in the files source code must be a zero. I would recommend including a copy of your source code's binaries in your submission.

Standard loopholes apply.

## Test Cases

(In ASCII encoding) Input:

"$&(*,.02468:<>@BDFHJLNPRTVXZ\^bdfhjlnprtvxz|~ Output: falsy Input: !#%')+-/13579;=?ACEGIKMOQSUWY[]_acegikmoqsuwy{} Output: truthy Input: LOREMIPSVMDOLORSITAMETCONSECTETVRADIPISCINGELITSEDDOEIVSMODTEMPORINCIDIDVNTVTLABOREETDOLOREMAGNAALIQVA VTENIMADMINIMVENIAMQVISNOSTRVDEXERCITATIONVLLAMCOLABORISNISIVTALIQVIPEXEACOMMODOCONSEQVAT DVISAVTEIRVREDOLORINREPREHENDERITINVOLVPTATEVELITESSECILLVMDOLOREEVFVGIATNVLLAPARIATVR EXCEPTEVRSINTOCCAECATCVPIDATATNONPROIDENTSVNTINCVLPAQVIOFFICIADESERVNTMOLLITANIMIDESTLABORVM Output: truthy  ## Tips • Choose language wisely this challenge might not be possible in every language • The Unix command xxd -b <file name> will print the binaries of a file to the console (along with some extra formatting stuff) • You may use other encodings other than ASCII such as UTF-8 as long as all other rules are followed • Some languages have a hard time reading multi-line input, but it's not like this challenge is meant to be easy, so it's probably OK. :P Can the input be empty? Aug 4, 2016 at 23:45 • !#%')+-/13579;=?ACEGIKMOQSUWY[]_acegikmoqsuwy{} are the banned printable ASCII characters, for anyone who cares. The allowed printable ASCII characters are "$&(*,.02468:<>@BDFHJLNPRTVXZ\^bdfhjlnprtvxz|~ Aug 4, 2016 at 23:48
• Quite handy that all vowels are banned... ;-) Aug 5, 2016 at 0:46
• Welp, so much for BF having a chance in this challenge.
– TLW
Aug 5, 2016 at 21:36
• Also note that if you have any line breaks in a DOS/Windows file, the [CR] has the odd bit. I was hoping that WhiteSpace was safe, but alas [TAB]. If you want to go old school, EBCDIC gives you three vowels. Aug 8, 2016 at 23:56

# GS2, 4 bytes

dΦ("


Try it online!

### Hexdump

0000000: 64 e8 28 22                                      d.("


### How it works

      (implicit) Read all input and push it on the stack.
Φ    Map the previous token over all characters in the string:
d       Even; push 1 for even characters, 0 for odd ones.
(   Take the minimum of the resulting list of Booleans.
"  Negate the minimum.


## Befunge, 36 bytes

I know this is an old question, but I wanted to give it a try because I thought it would be an interesting challenge in Befunge.

>~:0|
>20:>$.@ | " "< *8*82<^p24*  Try it online! It outputs 1 if the input is corrupted (i.e. contains an odd byte), and 0 if it's OK. Explanation The problem is how to determine odd bytes without having access to the / (divide) or % (modulo) commands. The solution was to multiply the value by 128 (the sequence 28*8**), then write that result into the playfield. On a strictly standard interpreter, playfield cells are signed 8 bit values, so an odd number multiplied by 128 becomes truncated to -1 while an even number becomes 0. The other trick was in reading the -1 or 0 back from the playfield without having access to the g (get) command. The workaround for this was to write the value into the middle of an existing string sequence (" "), then execute that sequence to push the enclosed value onto the stack. At that point, determining the oddness of the byte is a simple less-than-zero test. One final aspect worth discussing is the output. In the false case, we reach the >$. sequence with just one value on the stack, so $ clears the stack making the . output a zero. In the true case, we follow the path 20:>$.. Since two is greater than zero, the comparison pushes a one onto the stack, and the : makes a duplicate copy so the $ won't drop it before it gets output. • This may be late and new but it is already my favorite answer. Dec 1, 2016 at 3:53 • @WheatWizard I only just realised now why this answer has been getting so much attention. Thank you for the bounty! Dec 7, 2016 at 23:27 ## CJam (11 bytes) "r2":(~f&2b  Online demo Stripping away the tricks to avoid odd bytes, this reduces to q1f&2b  which reads the input, maps a bitwise AND with 1, and then performs a base conversion, giving zero iff all of the ANDs were zero. • This code is sad :( Dec 1, 2016 at 6:49 • Because it can only have half of the chars @betseg Dec 7, 2016 at 11:24 # Printable .COM file, 100 bytes ^FZjfDXVL\,LPXD$$4"PXD,lHPXDjJXDRDX@PXDjtXDH,nPXDj@XD4@PXD,ZHPXD4,@PXD4:4"PXDH,\PXD4"PXD,hPXDRDX@P\  Hexdump: 00000000 5e 46 5a 6a 66 44 58 56 4c 5c 2c 4c 50 58 44 24 |^FZjfDXVL\,LPXD$|
Z$% Input file name implicitly, read its raw bytes and push them as an array of chars 2\ % Modulo 2 z % Number of nonzero values. This gives the number of odd bytes. Implicitly display  # CJam, 1817 15 bytes "<rj":(((*~:|X&  Assumes that the locale is set to Latin-1. Try it online! ### How it works The straightforward solution goes as follows. q e# Read all input from STDIN and push it as a string on the stack. :i e# Cast each character to its code point. :| e# Take the bitwise OR of all code points. X e# Push 1. & e# Take the bitwise AND of the logical OR and 1.  Unfortunately, the characters q and i cannot appear in the source code. To work around this issue, we are going to create part of the above source code dynamically, then evaluate the string. "<rj" e# Push that string on the stack. :( e# Decrement all characters, pushing ";qi". ( e# Shift out the first character, pushing "qi" and ';'. ( e# Decrement ';' to push ':'. * e# Join "qi" with separator ':', pushing "q:i". ~ e# Evaluate the string "q:i", which behaves as explained before.  # Pyth, 20 13 bytes vj0>LhZ.BRj.z  Or in binary: 00000000: 01110110 01101010 00110000 00111110 01001100 01101000 vj0>Lh 00000006: 01011010 00101110 01000010 01010010 01101010 00101110 Z.BRj. 0000000c: 01111010 z  Try it online ### How it works  .z all lines of input j join on newline .BR convert each character to binary >LhZ take the last (0 + 1) characters of each binary string j0 join on 0 v evaluate as an integer  The resulting integer is truthy (nonzero) iff any of the bytes were odd. # Jelly, 13 bytes 24‘ịØBvF|\ṪBṪ  Expects the input as a quoted command-line argument. Try it online! ### Hexdump 0000000: 32 34 fc d8 12 42 76 46 7c 5c ce 42 ce 24...BvF|\.B.  • If it was not for the odd byte restriction, this would equally work at 6 bytes: O%2¬Ạ¬. Sep 19, 2016 at 14:50 # Retina, 106 bytes Removes every allowed character, then matches any remaining characters. Truthy values will be the number of characters found. Falsey values will be 0. "| |\$|&|\(|\*|,|\.|0|2|4|6|8|:|<|>|@|B|D|F|H|J|L|N|P|R|T|V|X|Z|\\|\^||b|d|f|h|j|l|n|p|r|t|v|x|z|\||~

.


Try it online

Since . doesn't match newlines by default, I don't have to remove them.

## Perl 5 + -p0, 136 bytes

Similar to other answers, this removes all even bytes and leaves any odd bytes (which is truthy).

tr<�
 "\$&(*,.02468:<>@BDFHJLNPRTVXZ\\^bdfhjlnprtvxz|~€‚„†ˆŠŒŽ’”–˜šœž ¢¤¦¨ª¬®°²´¶¸º¼¾ÀÂÄÆÈÊÌÎÐÒÔÖØÚÜÞàâäæèêìîðòôöøúüþ><>d


Try it online!

• -0 does nothing to newlines. It only determines how to split up the input, it doesn't remove any characters. Aug 17, 2017 at 16:34
• Ouch that's too bad. Aug 17, 2017 at 16:36
• @ØrjanJohansen Yeah, you're right about -0, I wanted to do the whole block as a lump, but that shouldn't matter, but I can't get around this... Too bad! I'll clean up these comments. Thanks for the heads up though! Aug 17, 2017 at 16:37
• So it works now? Guess I should delete some of the comments. From the edit diff, I see you're now including every even byte in the program. I think you might want to say that explicitly, since not all those characters show up (for me at least). Feb 6, 2018 at 17:20
• @ØrjanJohansen yes! I think I've got it now. I don't think all other answers cover all even bytes either, I think a few only work on printable ASCII. I'm pretty confident this does what I wanted now. I hope so anyway! Feb 6, 2018 at 17:33

# Japt, 10 bytes

ø0ôH² ®dZÄ


Try it online!

Japt's codepage is ISO-8859-1. The code gives false when itself is entered as a string, therefore a valid submission.

### Unpacked & How it works

Uø0ôHp2  mZ{ZdZ+1

Uø      Does input string contain any element in the following array...?
0ôHp2     Range of 0 to 32**2, inclusive
mZ{       Map...
ZdZ+1       Convert the number Z to a char having charcode 2*Z+1


Not having String.c (get charcode, or map over charcodes) was a pain, but fortunately there is Number.d (convert number to char).

Turns out that Japt wins over CJam, Pyth and Jelly :)

Without the restriction, there are a couple of ways to do it in 6 bytes (going par with CJam and Jelly again):

®c uÃn

Unpacked: UmZ{Zc u} n

UmZ{   Map on each char...
Zc u     Convert to charcode modulo 2
}
n      Convert the resulting string to number


"000..000" is converted to the number 0 (falsy) regardless of how long it is. On the other hand, anything that contains 1 is converted to a nonzero double, or Infinity if it's too big (both truthy).

¬d_c u

Unpacked: q dZ{Zc u

q    Convert to array of chars
dZ{  Is something true when mapped with...
Zc u   Convert each char to charcode modulo 2


More straightforward approach that directly yields true or false.

Or, 5 bytes solution is even possible with the help of -d flag:

¬®c u

Unpacked: q mZ{Zc u

q     Convert to array of chars
mZ{   Map...
Zc u    Convert to charcode modulo 2

Result is array of zeros and ones
-d    Apply .some() on the resulting array
`