C언어에서 !안쓰고 !연산값 구하기..

주재효의 이미지

int bang(int x){
return ?????;
}

ex)bang(3)=0, bang(234)=0, bang(0)=1

-허용연산자 : ~, &, ^, |, +, >>, <<
-연산자사용가능횟수: 12번
-제어문(for,if,switch,while등등)사용 불가
-(,),=는 무제한 사용가능
-변수 선언가능

도와주세요..ㅠ_ㅠ

Anonymouss의 이미지

꼭 무슨 강아지 시험하는듯한 질문이라 별로 답변달고 싶은 생각이 안드는 질문이군요. 사실 아무 쓸모도 없고 의미도 없고...

lovejin0309의 이미지

이왕이면 실명으로 의견을 올리시는게 좋을 듯 하고, 정답글을 올려도 괜찮지 않을까요? ㅎㅎ

(괜히 오바 하시는 것 같습니다.)

질문자의 이미지

무슨 이유인지 모르지만 제가 올린글이 짤렸네요..밑부분이 ..

허용 연산자는 : ~, &, ^, |, +, <<, >> 입니다
사용가능갯수는 12개까지고요
제어문 사용못하고, 변수선언가능합니다..

!x를 !안쓰고 구하는 거죠..!0=1, !3=0 이런거죠..

ㅡ,.ㅡ;;의 이미지

1 -( (1 & x) | (x>>1 & 1) | (x>>2 & 1)| (x>>3 & 1)|........| (x>>63 & 1))

-----------
64비트 체계까지 가능


----------------------------------------------------------------------------

ㅡ,.ㅡ;;의 이미지

더간단한 방법이 있었네...

1 - (x>>63 & 1 ) - (-x>>63 & 1 )

-------------------
테스트 안해봄..ㅡㅡ;;될꺼 같음...


----------------------------------------------------------------------------

ㅡ,.ㅡ;;의 이미지

교수님이 퀴즈내셨나요..??


----------------------------------------------------------------------------

주재효의 이미지

풀었어요..ㅋㄷ

(((~x+1)|x)>>31)+1 이렇게 하면 되네요..ㅋㄷ 답변들 감사요^^

ㅡ,.ㅡ;;의 이미지


그렇군요. 둘다되네요..

~사용하지않고 더간단히도 되네요

1 + ((x|-x)>>31);


----------------------------------------------------------------------------

thyoo의 이미지

#include "stdbool.h"
 
int bang(int x) { return (_Bool)(x) ^ 1); }

또는

int bang(int x) 
{
inline _Bool inner_bang(int x) { return x; }
return inner_bang(x) ^ true;
}

___________________________________
Less is More (Robert Browning)

___________________________________
Less is More (Robert Browning)

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.