小编saa*_*aad的帖子

我无法打印按位运算符的结果

可能重复:
我可以在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)

谢谢

c bitwise-operators

3
推荐指数
1
解决办法
466
查看次数

Nodejs http请求console.log函数打印两次

每当我使用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)

我的问题是:

  1. 为什么请求发送两次?
  2. 为什么在第二个请求中路径名为favicon.ico,尽管事实上我没有在请求URL中的套接字号后面指定任何内容?
  3. 有什么办法可以解决这两个问题吗?

谢谢.

javascript node.js

0
推荐指数
1
解决办法
1212
查看次数

标签 统计

bitwise-operators ×1

c ×1

javascript ×1

node.js ×1