小编sam*_*ray的帖子

C打印位

我试图在C中编写一个打印int的程序.由于某种原因我得到错误的价值观,

void printBits(unsigned int num){
    unsigned int size = sizeof(unsigned int);
    unsigned int maxPow = 1<<(size*8-1);
    printf("MAX POW : %u\n",maxPow);
    int i=0,j;
    for(;i<size;++i){
        for(j=0;j<8;++j){
            // print last bit and shift left.
            printf("%u ",num&maxPow);
            num = num<<1;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题,首先是为什么我得到这个结果(对于printBits(3)).

最大电平:2147483648 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 2147483648 214748364 8

第二是有更好的方法吗?

c

10
推荐指数
3
解决办法
5万
查看次数

播放框架2.0控制台错误

当试图在项目文件夹的窗口上运行新的play 2.0控制台(在cmd中键入'play')时(按框架web教程的指示).

我收到 :

C:\temp\play-2.0\play-2.0\todolist>play
[info] Loading project definition from C:\temp\play-2.0\play-2.0\todolist\projec
t
[error] Server access Error: Connection timed out: connect url=http://repo.types
afe.com/typesafe/ivy-releases/org.hibernate/hibernate-validator/4.2.0.Final/ivys
/ivy.xml
[error] Server access Error: Connection timed out: connect url=http://repo.types
afe.com/typesafe/ivy-releases/javax.validation/validation-api/1.0.0.GA/ivys/ivy.
xml
[error] Server access Error: Connection timed out: connect url=http://repo.types
afe.com/typesafe/ivy-releases/org.springframework/spring-context/3.0.7.RELEASE/i
vys/ivy.xml
[error] Server access Error: Connection timed out: connect url=http://repo.types
afe.com/typesafe/ivy-releases/org.springframework/spring-core/3.0.7.RELEASE/ivys
/ivy.xml
[error] Server access Error: Connection timed out: connect url=http://repo.types
afe.com/typesafe/ivy-releases/org.springframework/spring-beans/3.0.7.RELEASE/ivy
s/ivy.xml
Run Code Online (Sandbox Code Playgroud)

列表继续......

出了什么问题,为什么我想要做的就是使用console/run app来尝试访问远程位置?

playframework-2.0

8
推荐指数
1
解决办法
5406
查看次数

我怎么知道 calloc 是否无法初始化

我读过 calloc (malloc+init) 有时无法用零字节初始化数组(但仍会返回指向 malloc 数组的指针)。但在文档中它没有指定它将返回 NULL,有没有办法确保数组被初始化为零(然后遍历数组更好),如果不是, calloc 相对于 malloc 的优势是什么?

c calloc

2
推荐指数
1
解决办法
6294
查看次数

标签 统计

c ×2

calloc ×1

playframework-2.0 ×1