可能重复:
我可以在C或C++中使用二进制文字吗?
我无法在C中显示按位运算符的结果.在下面的代码中,a&b应为100001且a | b为111111.但是,打印结果不同.无论有没有itoa,我都试图这样做,但无济于事.为什么程序没有正确打印答案?
#include<stdio.h>
#include<stdlib.h>
int main (int argc, char* argv[]) {
unsigned a = 101101;
unsigned b = 110011;
unsigned c = a&b;
unsigned d = a|b;
char s[100];
char t[100];
itoa(c,s,2);
itoa(d,t,2);
printf("%s\n",s); /* Shouldn't it produce 100001?
Instead I get 11000100010101001*/
printf("%s\n",t); /* Ought to print 111111.
Instead it prints 11010111111111111 */
return 0;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
每当我使用node.js向服务器发出http请求时,http请求函数内的console.logs输出两次.我使用以下代码设置了一个服务器,并在firefox上使用localhost:8888发出请求(localhost:8888):
var http = require('http');
var url = require('url');
function onRequest(request, response) {
var pathname = url.parse(request.url, true).pathname;
console.log("Your url pathname is " + pathname);
response.write("Did you get your response?");
}
var new_server = http.createServer(onRequest).listen(8888);
Run Code Online (Sandbox Code Playgroud)
控制台打印:
Your url pathname is /
Your url pathname is /favicon.ico
Run Code Online (Sandbox Code Playgroud)
我的问题是:
谢谢.