{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/c-int-unsigned-int-binary-types/",
  "atlas": "https://www.pystone.net/?node=c-int-unsigned-int-binary-types#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/c-int-unsigned-int-binary-types.md",
  "context": "https://www.pystone.net/notes/c-int-unsigned-int-binary-types.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:c-int-unsigned-int-binary-types",
  "slug": "c-int-unsigned-int-binary-types",
  "title": "C语言int&unsigned int与二进制类型",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "C语言int&unsigned int与二进制类型",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "ef996b115c4665ca1690df54d3878f3d6e0785b57d7d3ffb905957894ab68c50",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "C语言int&unsigned int与二进制类型",
      "anchor": "c语言intunsigned-int与二进制类型",
      "citation": "https://www.pystone.net/notes/c-int-unsigned-int-binary-types/#c%E8%AF%AD%E8%A8%80intunsigned-int%E4%B8%8E%E4%BA%8C%E8%BF%9B%E5%88%B6%E7%B1%BB%E5%9E%8B"
    },
    {
      "depth": 2,
      "text": "C语言int&unsigned int与二进制类型",
      "anchor": "c语言intunsigned-int与二进制类型-1",
      "citation": "https://www.pystone.net/notes/c-int-unsigned-int-binary-types/#c%E8%AF%AD%E8%A8%80intunsigned-int%E4%B8%8E%E4%BA%8C%E8%BF%9B%E5%88%B6%E7%B1%BB%E5%9E%8B-1"
    },
    {
      "depth": 3,
      "text": "unsigned int",
      "anchor": "unsigned-int",
      "citation": "https://www.pystone.net/notes/c-int-unsigned-int-binary-types/#unsigned-int"
    },
    {
      "depth": 3,
      "text": "((signed)int)",
      "anchor": "signedint",
      "citation": "https://www.pystone.net/notes/c-int-unsigned-int-binary-types/#signedint"
    },
    {
      "depth": 3,
      "text": "char和int的转换",
      "anchor": "char和int的转换",
      "citation": "https://www.pystone.net/notes/c-int-unsigned-int-binary-types/#char%E5%92%8Cint%E7%9A%84%E8%BD%AC%E6%8D%A2"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:programming-languages-and-runtimes",
      "title": "编程语言与运行时",
      "url": "https://www.pystone.net/notes/programming-languages-and-runtimes/",
      "atlas": "https://www.pystone.net/?node=programming-languages-and-runtimes#knowledge-atlas",
      "label": "编程语言与运行时",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "C++中的“C语言int&unsigned int与二进制类型”导航项",
      "citation": "https://www.pystone.net/notes/programming-languages-and-runtimes/#c"
    }
  ],
  "contentMarkdown": "# C语言int&unsigned int与二进制类型\n\n﻿# C语言int&unsigned int与二进制类型\n\n> 创建时间：2020/3/31 11:52\n\n## C语言int&unsigned int与二进制类型\n\n**任何数据都是以其二进制的补码形式存储在内存中的**\nint占几个字节是与电脑编译器有关的。不过现在大部分电脑int占4个字节，即32位\n\n### unsigned int\n\n32个0~32个1，即：0~4294967295\n\nshort int 是16位的，无符号的范围是0~65535\n\n### ((signed)int)\n\nint实际上是signed int ，我们通常省略signed\n补码表示\n范围：-2147483648~2147483647\n\n```cpp\nstring str1 = &quot;test&quot;;\nstring str2 = &quot;test&quot;;\n\n```\n\n### char和int的转换\n\n```cpp\nstring str1 = &quot;test&quot;;\nstring str2 = &quot;test&quot;;\n\n```\n\nint转换成char会切割\nchar转换成int又会在前面全加上1\n\n130转换成char的时候它在内存中变成了\n1000 0010\n再转换成int类型就会变成\n1111 1111 1111 1111 1111 1111 1000 0010（\n补码）\n\n输出的时候要输出原码\n转换成原码：\n1000 0000 0000 0000 0000 0000 0111 1110\n所以最后的结果就是-126\n"
}
