7.24 資料類型運算子 補碼

來源:互聯網
上載者:User

標籤:style   http   color   io   使用   ar   資料   div   sp   

資料類型:long           32位4個位元組   64位8個位元組                       vs2013 4個位元組long long  8個位元組float   4個位元組double 8個位元組
%x和%p的區別:int main(){
 int num = 256; printf("%p\n",&num);  //0107FAFC printf("%#p\n", &num); //0X0107FAFC
 printf("%x\n", &num); //107fafc printf("%#x\n", &num); //0x107fafc
}
補碼:正數  原碼 反碼 補碼 一樣負數        負數的原碼               符號位是1   其他位正常        負數的原碼轉補碼              除符號位取反 再加1  //  1000 0011 --> 11111101     負數的補碼轉原碼              除符號位取反 再加1
-5     原碼1000 0101        補碼1111 1011
        原碼1000 0101
截斷:
  1. #include <stdio.h>
  2. int main()
  3. {
  4. int num = 5555;                    //十六進位0x15b3 小端儲存 b3 15 -----記憶體
  5. unsigned char c = num; // b3 只留下低位元組
  6. printf("%d\n", c);               //輸出179
  7. }



unsigned 類型 與 int 相加出現的bug :unsigned int a = 6;a+ -10 > 0  //這句話是對的   因為-10是int  轉為unsigned int      負數就會變成一個非常大的正數                    //相加絕對大於0
  1. #include <stdio.h>
  2. int main()
  3. {
  4. unsigned int a = 6;
  5. if (a - 10 > 0) //結果會當成一個無符號整形來看待
  6. {
  7. printf("aaaaaaaaa\n");
  8. }
  9. }
結果會輸出aaaaaaaaa


3.14 :   3.14  預設是double型要想變成float型 就要使用 3.14f

,(逗號)運算子 :結果是最後一個值  int max = 5,6,10;   => max=10;

%求餘運算子 :負數可以求餘,結果和被除數符號一致但是浮點數不能求餘

來自為知筆記(Wiz)

7.24 資料類型運算子 補碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.