公告版位
沒有痛苦 就沒有收穫
若內容對你有幫助,可以留言讓我知道哦~
有問題想要諮詢可以請至這裡連絡我哦 =>不會就放這邊
目前分類:C (41)
- Apr 16 Sun 2023 01:58
使用巨集寫出找出最小值
- Jan 20 Wed 2021 23:51
【CodeType】直接設定bit設定為0或1
- Jan 20 Wed 2021 23:33
【CodeType】union 8bit 和 4byte寫法
#include <stdio.h> union{ int myint; struct { char char4; char char3; char char2; char char1; } myChars; }myUnion; union{ char mychar; struct { unsigned bit0 :1; unsigned bit1 :1; unsigned bit2 :1; unsigned bit3 :1; unsigned bit4 :1; unsigned bit5 :1; unsigned bit6 :1; unsigned bit7 :1; }bits; }cc; int main() { myUnion.myint = 0x11223344; printf("1=%x\n", myUnion.myChars.char1); printf("2=%x\n", myUnion.myChars.char2); printf("3=%x\n", myUnion.myChars.char3); printf("4=%x\n", myUnion.myChars.char4); //yourUnion.yourSplitInterger = 0x1234; cc.bits.bit0 = 1; return 0; }
- Nov 17 Tue 2020 11:21
【CodeType】C語言的0xFul代表是什麼
- Oct 09 Wed 2019 11:24
【C】產生10個介於0~99之間的亂數
Turbo C/C++ 以產生10個介於0~99之間的亂數為例
#include<stdio.h> #include<stdlib.h> int main(){ int a,times=0; randomize(); while(times<=10){ a=random(100); printf("%d\n",a); times++; } puts("\n"); return 0; }
- Sep 20 Fri 2019 15:43
【C】(int*)意思
- Sep 20 Fri 2019 15:27
【C】重要的C語言問題
Q1:預處理器 (Preprocessor),用預處理指令 #define 宣告一個常數,用以表示 1 年中有多少秒 (忽略閏年問題)。
ANS:#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL
- Jul 29 Mon 2019 10:14
【CodeType】2 bytes(十六進制) to Decimal(十進制)
今天要說明的是,在C語言中,2個byte如果要轉十進制 如何做?
2個byte分別為high byte 和 low byte,可以組合成一個0-65535大小的十進制 ,
在C語言可以這樣寫:
- Jul 29 Mon 2019 09:09
C語言 - printf之變數參數
- Nov 26 Mon 2018 09:33
C範例 - 輸入判斷
C範例 - 輸入判斷程式碼
printf("開始燒錄? 輸入 Y or N :\n"); char c; scanf("%c", &c); while (c == 'Y' || c =='N' || c =='y' || c== 'n'){ if (c == 'Y' || c =='y') break; else exit(1); }
- Nov 23 Fri 2018 16:26
C範例 - do while 按下q離開
do { //一直做放這邊的程式 直到你按下q }while(ch!='q');
- Nov 23 Fri 2018 08:47
C範例 - UART傳送與接收程式
步驟1
先下載 RS232 for Windows Librery → http://www.teuniz.net/RS-232/
將 RS-232.tar.gz 解壓縮,只需要 rs232.c 和 rs232.h 即可。
- Aug 08 Wed 2018 10:41
C語法 - printf 兩個位元補0
C語法 - printf 兩個位元補0
printf("%02x\n", buffer[i]); //兩個位元補0
- Aug 08 Wed 2018 10:40
C範例 - 程式執行時間的方法
C語言紀錄程式執行時間的方法
最近一直在比程式的執行速度,測的方法又五花八門@@
這邊就記一個用time.h中的函式來計算所花時間的辦法:
- Aug 08 Wed 2018 10:39
【C語言】浮點數相加
C語言浮點數相加語法
printf("Temperature Channel %d = %6.2f ℃\n", index, (float)((temperature >>6) & 0x1ff) + (((float)(temperature & 0x3f)) * 0.015625));
- Aug 08 Wed 2018 10:38
C語言 - uint8_t, uint16_t, uint32_t, uint64_t
型態 uint8_t, uint16_t, uint32_t, uint64_t分別可以對照成
型態 usigned char, unsigned short, unsigned int, unsigned long long
那麼他們各自的範圍又是如何呢?
- Aug 08 Wed 2018 10:35
C範例- SCANF兩個輸入
C範例- SCANF兩個輸入
while(1) { listitem(); scanf ("%d",&cmd); //第一個輸入 scanf ("%x",&str); //x 十六進制 第二個輸入 printf("QQQQQQ= 0x%x\n", str); switch (cmd) { case 1: pwm.frequency = F1; pwm.type = MT; pwm.ctrl_pin = P0; pwm.duty_cycle = str; ioctl(fd, PWM_SET, &pwm); break; }
- Aug 08 Wed 2018 10:34
C範例 - 0x10變0X80
0x10變0X80 C語言
char upset(char dat) { //用 12345678 dat=(dat>>4)|(dat<<4); //dat 變成 56781234 dat=((dat&0xcc)>>2)|((dat&0x33)<<2);//dat=78563412 dat=((dat&0xaa)>>1)|((dat&0x55)<<1);//dat=87654321 return dat; }
- May 11 Fri 2018 12:01
C語法 - scanf Enter 誤判的問題
- May 11 Fri 2018 11:51
C範例 - 四個數字 從小排到大 由大排到小
四個數字 從小排到大 由大排到小
#include <stdio.h> int main(){ int a,b,c,d; int temp=0; scanf("%d%d%d%d",&a,&b,&c,&d); if (a>b){ temp =a; a=b; b=temp; } if (a>c){ temp =a; a=c; c=temp; } if (a>d){ temp =a; a=d; d=temp; } if (b>a){ temp =b; b=a; a=temp; } if (b>c){ temp =b; b=c; c=temp; } if (b>d){ temp =b; b=d; d=temp; } if (c>a){ temp =c; c=a; a=temp; } if (c>b){ temp =c; c=b; b=temp; } if (c>d){ temp =c; c=d; d=temp; } if (d>a){ temp =d; d=a; a=temp; } if (d>b){ temp =d; d=b; b=temp; } if (d>c){ temp =d; d=c; c=temp; } printf("%d%d%d%d\n",a,b,c,d); if (a<b){ temp =a; a=b; b=temp; } if (a<c){ temp =a; a=c; c=temp; } if (a<d){ temp =a; a=d; d=temp; } if (b<a){ temp =b; b=a; a=temp; } if (b<c){ temp =b; b=c; c=temp; } if (b<d){ temp =b; b=d; d=temp; } if (c<a){ temp =c; c=a; a=temp; } if (c<b){ temp =c; c=b; b=temp; } if (c<d){ temp =c; c=d; d=temp; } if (d<a){ temp =d; d=a; a=temp; } if (d<b){ temp =d; d=b; b=temp; } if (d<c){ temp =d; d=c; c=temp; } printf("%d%d%d%d",a,b,c,d); }