'2진수 표기'에 해당되는 글 1건

  1. 2011.12.28 gcc의 2진수 표기법
프로그램 사용/gcc2011. 12. 28. 11:05
기억력 감퇴인가.. 아무튼 c언어에서는 2진수 표기를 할 방법이 없어서
16진수로만 하는데 검색을 하다 보니 이상한 문장을 발견 -_-
  
보통 c에서는 00111111b 와 같이 사용하는데, 2진수로 바로 쓰려면 어떻게 해야하나요?
아시는 분 있으면 답변해주시면 감사하겠습니다. ^^; 

[링크 : http://www.terabank.co.kr/bbs/zboard.php?id=comunity01...no=1343]
[링크 : http://donghwada.tistory.com/entry/ATmega-Pin-Configurations-DDR-PORT-PIN]

gcc에서 제공하는 비표준 C문법으로
0x0000 이라고 16진수를 입력하듯
0b0000 이라고 2진수를 입력이 가능하다.

물론 vi에서도 인식되지 않는 문법이라 문법강조도 되지 않음 -_-
+ winavr역시 gcc 의 한 종류 이므로 이러한 문법을 허용한다.

$ vi temp.c 
  1 #include <stdio.h>
  2
  3 void main()
  4 {
  5     unsigned char binval = 0b1000000;
  6     unsigned char binval2= 10000;
  7 }
 
$ gcc temp.c
temp.c: In function ‘main’:
temp.c:6: warning: large integer implicitly truncated to unsigned type 

Most people use hexadecimal for binary numbers in C.
(GCC and some other compilers have an non-standard 0b####### extension

[링크 : http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=64658]  

흐음.. C99 표준에 넣으려다가 기각당했군 -ㅁ-
dl8dtl - Nov 26, 2006 - 08:38 PM
Post subject: RE: Binary constants in IAR C ?
> Binary notation was added in C99 if I remember correctly. 

No, it's been rejected by the committee. 

In the C99 rationale, you can find under 6.4.4.1 Integer constants: 

``A proposal to add binary constants was rejected due to 
lack of precedent and insufficient utility.'' 

So please tell your (national) standards body there *is* sufficient utility for 
it. As for the first part, I'm trying to get the 0b patch officially 
as an extension into GCC. Once that happened, there will be at least 
one very prominent C implementation that sets a precedent case. ;-) 
All those microcontroller implementations are probably nothing the ISO 
C standardization body might be aware of, but for sure, GCC is. 

> IAR is not fully up to C99 yet, 

It's about the most complete C99 implementation I've seen.  

[링크 : http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=44082&start=0]

그나저나.. 0000b 는 누구 문법일까?
Posted by 구차니