여러코드를 코드를 보다보면 이렇게도 응용을 할수 있구나라는 생각이든다.

과연 그 코드를 모르는 상태에서 이러한 코드를 생성할수 있을까...

/*10진수를 16진수로 출력하는 프로그램*/
#include <stdio.h>

void main()
{
 int input;
 int low, hi;

 while(1)
 {
  printf("0~255사이의 수를 입력하시오: ");
  scanf("%d", &input);
 
  hi = input >> 4;
  low = input & 0xf;
  printf("입력한 수의 16진 표기 = %c%c\n", hi+'0'+(hi > 9)*7, low+'0'+(low > 9)*7);

 }
}

10진에서 16진수를 구하기 위해 상위비트는 비트연산자를 통해 구하고

하위비트는 논리연산자로  마스크(?)를 만들어서 변수에 저장 시켰다.

그리고 나서 이를 16진수로 바꾸기 위해서 0의 아스키코드값 48과 더하면 9를 초과하는지의

여부를 알 수 있다. (hi >9)가 참이면 1 아니면 0을 리턴하는 것을 응용하여 9를 초과 했다면

아스키코드값이 대문자 A가 부터 표현하기 위해 7을 더해준다. (브라보!)

Trackback Address :: 이 글에는 트랙백을 보낼 수 없습니다

댓글을 달아 주세요

  1. 방돌 2011/07/05 15:00  address  modify / delete  reply

    hex 값 표현 하는 부분을 정말 많이 고민했었는데 이렇게 쉽게 풀리네요!
    좋은 자료 감사합니다~

  2. cctv drain survey winchester 2024/08/22 01:03  address  modify / delete  reply

    Ӏ think what yoou published made a bunch of sеnse.However, whuat about this?
    ssuppose уou added a little infߋгmation? I mean, I don't wat to tell you howw to rᥙn y᧐ur website, but wha
    if you added a post title that makes peole desire
    moгe? I mean 지나간 삶 :: 3.15(목) 비트연산자 활용,
    16진수구하기 iis a lttle vanilⅼɑ.Yоu could peek at Ⲩahoo's ront
    page and see how thеy create article headlines to
    get viewers to click. You might try adding a video oߋr a гelated
    ppic or two to grab readеrs interested about
    everүthing've written. Just my opіnion, it might make your ԝebsite
    a lіttle biіt more interesting.

  3. 출장안마 2024/08/25 08:52  address  modify / delete  reply

    WOW just what I was searching for. Came here by
    searching for 강서구출장마사지

  4. 초읍출장안마 2024/08/26 18:46  address  modify / delete  reply

    Yes! Finally someone writes about 초읍출장마사지.

  5. 서울 마사지 2024/08/28 20:53  address  modify / delete  reply

    Thanks for finally talking about >지나간 삶 :: 3.15(목) 비트연산자 활용,16진수구하기 <Liked it!

  6. 일산지출장안마 2024/08/28 21:08  address  modify / delete  reply

    Thanks for finally writing about >지나간 삶 :: 3.15(목) 비트연산자 활용,
    16진수구하기 <Loved it!

  7. 초읍출장 2024/08/28 21:19  address  modify / delete  reply

    I believe what you said made a great deal of sense. However, think on this, what if you added
    a little content? I ain't saying your information isn't good.,
    but what if you added a post title that makes people desire more?

    I mean 지나간 삶 :: 3.15(목) 비트연산자 활용,16진수구하기
    is a little vanilla. You ought to look at Yahoo's front page and watch how they create news
    headlines to grab viewers to open the links. You might add a video or a related pic
    or two to grab people interested about everything've written.
    Just my opinion, it could bring your blog a
    little bit more interesting.

  8. 경기광주출장마사지 2024/08/29 23:05  address  modify / delete  reply

    WOW just what I was looking for. Came here by searching
    for 안양출장마사지

  9. 초읍출장마사지 2024/08/30 16:29  address  modify / delete  reply

    Thanks for finally writing about >지나간 삶 :: 3.15(목) 비트연산자 활용,16진수구하기 <Liked it!

  10. 분당출장안마 2024/08/31 00:59  address  modify / delete  reply

    Thanks for finally talking about >지나간 삶 :: 3.15(목) 비트연산자 활용,16진수구하기 <Loved it!

  11. 고양출장안마 2024/09/02 02:39  address  modify / delete  reply

    I believe everything posted made a great
    deal of sense. However, what about this? suppose you wrote a catchier
    post title? I am not saying your content isn't good., however what if you added something that grabbed people's attention? I mean 지나간 삶 ::
    3.15(목) 비트연산자 활용,16진수구하기 is a little
    vanilla. You should look at Yahoo's front page and see how they write news titles to grab
    viewers to click. You might try adding a video or
    a pic or two to get people interested about what you've got to say.

    Just my opinion, it could bring your blog a little livelier.

  12. 용원출장안마 2024/09/02 03:58  address  modify / delete  reply

    I think everything said was very logical. However, think on this, what if you were to write a awesome title?
    I am not suggesting your content is not solid., however what if you added a headline that grabbed folk's attention? I mean 지나간 삶 :: 3.15(목)
    비트연산자 활용,16진수구하기 is kinda plain. You ought to peek at Yahoo's front
    page and watch how they create news headlines to get viewers interested.

    You might add a related video or a pic or two to grab readers interested about everything've got to say.

    Just my opinion, it could bring your posts a little livelier.

  13. 인천출장안마 2024/09/03 21:20  address  modify / delete  reply

    WOW just what I was searching for. Came here by searching for 강서구출장안마

  14. 용원출장 2024/09/04 01:41  address  modify / delete  reply

    WOW just what I was searching for. Came here by searching for 용원출장

  15. blocked drains dorchester 2024/09/06 08:37  address  modify / delete  reply

    Ꭲhankѕ for finaⅼly talking about >지나간 삶 :: 3.15(목) 비트연산자 활용,16진수구하기 <Liked it!

[로그인][오픈아이디란?]