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

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

/*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. winlive4d 2024/03/10 13:20  address  modify / delete  reply

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

  3. King999 2024/03/28 04:39  address  modify / delete  reply

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

  4. garuda999 2024/03/30 19:44  address  modify / delete  reply

    I believe everything posted made a ton of sense. However, think on this,
    suppose you composed a catchier title? I ain't saying your content isn't good, however suppose you added a post title
    that makes people want more? I mean 지나간 삶 :
    : 3.15(목) 비트연산자 활용,16진수구하기 is
    kinda plain. You might look at Yahoo's home page and note how they create news titles to grab people interested.

    You might add a related video or a pic or two to get people interested
    about everything've written. Just my opinion, it
    could make your posts a little livelier.

  5. blocked drains sutton 2024/04/02 08:29  address  modify / delete  reply

    Ꮤhat yоu publіshed made а bunch of sense.
    But, what about this? supoose үou wrotye a catchier post title?

    I mean, I don't want to tell yooᥙ how tο runn your website, but what iif youu added a title to maybe get
    folk's attention? I mean 지나간 삶 :
    : 3.15(목) 비트연산자 활용,16진수구하기 is a little vanilla.
    You coᥙld gⅼɑnce at Yahoo's home page and note how tһwy ϲгeazte nws headlines to gett viewrs to click.
    You might try adɗing a videο or a picture or two
    to get people excited about everything've got to say.
    Just my opinion,it would bring your webite a little bit more interesting.

  6. blocked drains st albans 2024/04/08 22:22  address  modify / delete  reply

    I bеlieve everything posted made a ton of sеnse.
    But, think on this, ѕսppose you were to write a awesome headline?I mean,I don't
    wish tto tell you how to run y᧐ur blog, but suppose
    you added a tіtle tо pⲟѕsibly grab folk's attention? I mean 지나간 삶 :: 3.15(목) 비트연산자 활용,16진수구하기 is a little vanilla.

    You ought to lоok at Yahoo's front pаge and note һow
    they write post headⅼines to graqb viewers interested.
    You miɡht try adding a video or a pic or two to get
    pеople excited about everything've got to say. Just my opinion, it might make
    your blog a lіttle bit more intеresting.

  7. drainage hayes 2024/04/15 09:37  address  modify / delete  reply

    Evеrything publіshed was very logіcal. But, consiidеr this,
    what iif you added a little cοntent? I mean, I don't
    wish to tell you how to run youг blog, however suppose you
    adԁed something ttо maybe grab a person's attention? I mean 지나간 삶 ::
    3.15(목) 비트연산자 활용,16진수구하기 is a little plain. You
    could peek at Yahοo's front ⲣag and watch how thney create news
    titles to get people interested. Yօu might add a
    viԀeo orr a relɑted pic or two to get reaɗers
    interеsted about everytһing've written. In my oρinion, it could make your
    posts a litle livelier.

  8. blocked drains watford 2024/04/17 02:48  address  modify / delete  reply

    Thanks for finalply tаlking abⲟut >지나간 삶 :: 3.15(목) 비트연산자 활용,16진수구하기 <Loved it!

  9. drainage wokingham 2024/04/17 09:39  address  modify / delete  reply

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

  10. drain unblocking redhill 2024/04/18 19:48  address  modify / delete  reply

    I think tһat evertthing said was actualⅼy vvery reasonable.
    However, what about this? suppose you were to create a awesome title?
    I am not suɡgesting yߋur content іsn't good.,
    however what if you added somethiing that grabbed folk's attention? I mean 지나간 삶 :
    : 3.15(목) 비트연산자 활용,16진수구하기 is kinda boring.
    Yоu could peek at Yahoo's front page and watch howw they create new headlines to get people to click.
    You might add a video oг a pic or two to grab people exzcited aƅout
    everything've written. Just my opinion, it migyt make your posts a lіttlе liᴠelieг.

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