Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#JavaScript (ES6), (削除) 92 (削除ここまで)(削除) 87 (削除ここまで) 81

JavaScript (ES6), (削除) 92 (削除ここまで)(削除) 87 (削除ここまで) 81

Function getting and returning an integer in MSB.
The implementation is straightforwrd following @randomra comment:

  • calc p3wrong|p2wrong|p1wrong (line 2,3,4)
  • use it as a bit mask to flip the incorrect bit (line 1),
  • then return just the data bits (last line)
F=w=>(w^=128>>(
 (w^w*2^w*4^w/2)&4|
 (w/8^w^w*2^w/16)&2|
 (w/16^w/4^w^w/64)&1
))&7|w/2&8

Test In Frefox/FireBug console

;[0b1110000,0b1100000,0b1111011,0b0110001,
0b1011011,0b0101001,0b1010000,0b0100010]
.map(x=>x.toString(2)+'->'+F(x).toString(2))

Output

["1110000->1000", "1100000->1000", "1111011->1111", "110001->1011", "1011011->1010", "101001->1", "1010000->1000", "100010->10"]

#JavaScript (ES6), (削除) 92 (削除ここまで)(削除) 87 (削除ここまで) 81

Function getting and returning an integer in MSB.
The implementation is straightforwrd following @randomra comment:

  • calc p3wrong|p2wrong|p1wrong (line 2,3,4)
  • use it as a bit mask to flip the incorrect bit (line 1),
  • then return just the data bits (last line)
F=w=>(w^=128>>(
 (w^w*2^w*4^w/2)&4|
 (w/8^w^w*2^w/16)&2|
 (w/16^w/4^w^w/64)&1
))&7|w/2&8

Test In Frefox/FireBug console

;[0b1110000,0b1100000,0b1111011,0b0110001,
0b1011011,0b0101001,0b1010000,0b0100010]
.map(x=>x.toString(2)+'->'+F(x).toString(2))

Output

["1110000->1000", "1100000->1000", "1111011->1111", "110001->1011", "1011011->1010", "101001->1", "1010000->1000", "100010->10"]

JavaScript (ES6), (削除) 92 (削除ここまで)(削除) 87 (削除ここまで) 81

Function getting and returning an integer in MSB.
The implementation is straightforwrd following @randomra comment:

  • calc p3wrong|p2wrong|p1wrong (line 2,3,4)
  • use it as a bit mask to flip the incorrect bit (line 1),
  • then return just the data bits (last line)
F=w=>(w^=128>>(
 (w^w*2^w*4^w/2)&4|
 (w/8^w^w*2^w/16)&2|
 (w/16^w/4^w^w/64)&1
))&7|w/2&8

Test In Frefox/FireBug console

;[0b1110000,0b1100000,0b1111011,0b0110001,
0b1011011,0b0101001,0b1010000,0b0100010]
.map(x=>x.toString(2)+'->'+F(x).toString(2))

Output

["1110000->1000", "1100000->1000", "1111011->1111", "110001->1011", "1011011->1010", "101001->1", "1010000->1000", "100010->10"]
Changed order of byte changes, because of the leaderboard
Source Link
Jakube
  • 22k
  • 3
  • 28
  • 108

#JavaScript (ES6) 81, (削除) 92 (削除ここまで) (削除) 87 92 (削除ここまで) 81

Function getting and returning an integer in MSB.
The implementation is straightforwrd following @randomra comment:

  • calc p3wrong|p2wrong|p1wrong (line 2,3,4)
  • use it as a bit mask to flip the incorrect bit (line 1),
  • then return just the data bits (last line)
F=w=>(w^=128>>(
 (w^w*2^w*4^w/2)&4|
 (w/8^w^w*2^w/16)&2|
 (w/16^w/4^w^w/64)&1
))&7|w/2&8

Test In Frefox/FireBug console

;[0b1110000,0b1100000,0b1111011,0b0110001,
0b1011011,0b0101001,0b1010000,0b0100010]
.map(x=>x.toString(2)+'->'+F(x).toString(2))

Output

["1110000->1000", "1100000->1000", "1111011->1111", "110001->1011", "1011011->1010", "101001->1", "1010000->1000", "100010->10"]

#JavaScript (ES6) 81 (削除) 87 92 (削除ここまで)

Function getting and returning an integer in MSB.
The implementation is straightforwrd following @randomra comment:

  • calc p3wrong|p2wrong|p1wrong (line 2,3,4)
  • use it as a bit mask to flip the incorrect bit (line 1),
  • then return just the data bits (last line)
F=w=>(w^=128>>(
 (w^w*2^w*4^w/2)&4|
 (w/8^w^w*2^w/16)&2|
 (w/16^w/4^w^w/64)&1
))&7|w/2&8

Test In Frefox/FireBug console

;[0b1110000,0b1100000,0b1111011,0b0110001,
0b1011011,0b0101001,0b1010000,0b0100010]
.map(x=>x.toString(2)+'->'+F(x).toString(2))

Output

["1110000->1000", "1100000->1000", "1111011->1111", "110001->1011", "1011011->1010", "101001->1", "1010000->1000", "100010->10"]

#JavaScript (ES6), (削除) 92 (削除ここまで) (削除) 87 (削除ここまで) 81

Function getting and returning an integer in MSB.
The implementation is straightforwrd following @randomra comment:

  • calc p3wrong|p2wrong|p1wrong (line 2,3,4)
  • use it as a bit mask to flip the incorrect bit (line 1),
  • then return just the data bits (last line)
F=w=>(w^=128>>(
 (w^w*2^w*4^w/2)&4|
 (w/8^w^w*2^w/16)&2|
 (w/16^w/4^w^w/64)&1
))&7|w/2&8

Test In Frefox/FireBug console

;[0b1110000,0b1100000,0b1111011,0b0110001,
0b1011011,0b0101001,0b1010000,0b0100010]
.map(x=>x.toString(2)+'->'+F(x).toString(2))

Output

["1110000->1000", "1100000->1000", "1111011->1111", "110001->1011", "1011011->1010", "101001->1", "1010000->1000", "100010->10"]
deleted 4 characters in body
Source Link
edc65
  • 32.3k
  • 3
  • 37
  • 90

#JavaScript (ES6) 8781 (削除) 9287 92 (削除ここまで)

Function getting and returning an integer in MSB.
The implementation is straightforwrd following @randomra comment:

  • calc p3wrong|p2wrong|p1wrong (line 2,3,4)
  • use it as a bit mask to flip the incorrect bit (line 1),
  • then return just the data bits (last line)
F=w=>(w^=128>>(
 ((w^w*2^w*4^w/2)&4)|&4|
 ((w/8^w^w*2^w/16)&2)|&2|
 ((w/16^w/4^w^w/64)&1)
))&7|w/2&8

Test In Frefox/FireBug console

;[0b1110000,0b1100000,0b1111011,0b0110001,
0b1011011,0b0101001,0b1010000,0b0100010]
.map(x=>x.toString(2)+'->'+F(x).toString(2)))

Output

["1110000->1000", "1100000->1000", "1111011->1111", "110001->1011", "1011011->1010", "101001->1", "1010000->1000", "100010->10"]

#JavaScript (ES6) 87 (削除) 92 (削除ここまで)

Function getting and returning an integer in MSB.
The implementation is straightforwrd following @randomra comment:

  • calc p3wrong|p2wrong|p1wrong (line 2,3,4)
  • use it as a bit mask to flip the incorrect bit (line 1),
  • then return just the data bits (last line)
F=w=>(w^=128>>(
 ((w^w*2^w*4^w/2)&4)|
 ((w/8^w^w*2^w/16)&2)|
 ((w/16^w/4^w^w/64)&1)
))&7|w/2&8

Test In Frefox/FireBug console

;[0b1110000,0b1100000,0b1111011,0b0110001,
0b1011011,0b0101001,0b1010000,0b0100010]
.map(x=>x.toString(2)+'->'+F(x).toString(2)))

Output

["1110000->1000", "1100000->1000", "1111011->1111", "110001->1011", "1011011->1010", "101001->1", "1010000->1000", "100010->10"]

#JavaScript (ES6) 81 (削除) 87 92 (削除ここまで)

Function getting and returning an integer in MSB.
The implementation is straightforwrd following @randomra comment:

  • calc p3wrong|p2wrong|p1wrong (line 2,3,4)
  • use it as a bit mask to flip the incorrect bit (line 1),
  • then return just the data bits (last line)
F=w=>(w^=128>>(
 (w^w*2^w*4^w/2)&4|
 (w/8^w^w*2^w/16)&2|
 (w/16^w/4^w^w/64)&1
))&7|w/2&8

Test In Frefox/FireBug console

;[0b1110000,0b1100000,0b1111011,0b0110001,
0b1011011,0b0101001,0b1010000,0b0100010]
.map(x=>x.toString(2)+'->'+F(x).toString(2))

Output

["1110000->1000", "1100000->1000", "1111011->1111", "110001->1011", "1011011->1010", "101001->1", "1010000->1000", "100010->10"]
added 7 characters in body
Source Link
edc65
  • 32.3k
  • 3
  • 37
  • 90
Loading
Source Link
edc65
  • 32.3k
  • 3
  • 37
  • 90
Loading

AltStyle によって変換されたページ (->オリジナル) /