Skip to content

Instantly share code, notes, and snippets.

View beiweiqiang's full-sized avatar
🎯
Focusing

beiweiqiang beiweiqiang

🎯
Focusing
  • Guangzhou, China
View GitHub Profile
@beiweiqiang
beiweiqiang / example.py
Last active March 8, 2017 12:45
python triangles
def triangles(max):
n = 3
my_list = [1]
if max > 1:
yield my_list
if max > 2:
my_list = [1, 1]
yield my_list
while n <= max:
; (function (window, $) {
'use strict';
var $scrollTo;
var timer = null;
var scrollTop = 0;
window.onscroll = function () {
scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
};
@beiweiqiang
beiweiqiang / main.c
Last active June 20, 2018 14:20
取得一个 int 类型的最高字节
#include <stdio.h>
int get_msb(int w);
int main() {
int x = 2147483647;
printf("%zd %d\n", sizeof(int), get_msb(x));
return 0;
}
@beiweiqiang
beiweiqiang / main.c
Created June 20, 2018 14:33
所有位为 1 时返回 1, 其他情况返回 0
#include <stdio.h>
/*
* 所有位都为 1 时返回 1, 其他条件下产生 0
* */
int get_result(int x);
int main() {
printf("%d \n", get_result(1));
printf("%d \n", get_result(-1));
@beiweiqiang
beiweiqiang / main.c
Created June 20, 2018 14:37
所有位为 0 时返回 1, 其它情况返回 0
#include <stdio.h>
/*
* 所有位都为 0 时返回 1, 其他条件下产生 0
* */
int get_result(int x);
int main() {
printf("%d \n", get_result(1));
printf("%d \n", get_result(-1));
@beiweiqiang
beiweiqiang / main.c
Last active June 20, 2018 23:44
最低有效字节中的位都为 1, 则返回 1, 其他条件下产生 0
#include <stdio.h>
/*
* 最低有效字节中的位都为 1, 则返回 1, 其他条件下产生 0
* */
int get_result(int x);
int main() {
printf("%d \n", get_result(1));
printf("%d \n", get_result(-1));
@beiweiqiang
beiweiqiang / main.c
Created June 20, 2018 23:58
最高有效字节中的位都为 0, 则返回 1, 其他条件下产生 0
#include <stdio.h>
/*
* 最高有效字节中的位都为 0, 则返回 1, 其他条件下产生 0
* */
int get_result(int x);
int main() {
printf("%d \n", get_result(1));
printf("%d \n", get_result(-1));
@beiweiqiang
beiweiqiang / main.c
Last active June 21, 2018 00:28
如果机器是对 int 类型数使用算术右移, 返回 1, 其他返回 0
#include <stdio.h>
/*
* CSAPP exercise 2.62
* */
/*
* 如果机器是对 int 类型数使用算术右移, 返回 1, 其他返回 0
* */
int int_shifts_are_arithmetic();
@beiweiqiang
beiweiqiang / main.c
Created June 22, 2018 14:27
用算术右移, 完成逻辑右移; 用逻辑右移, 完成算术右移
#include <stdio.h>
/*
* CSAPP exercise 2.63
* */
/*
* 用算术右移, 完成逻辑右移
* */
unsigned srl(unsigned x, int k);
@beiweiqiang
beiweiqiang / main.c
Created June 23, 2018 00:45
当所有奇数位为 1, 返回 1
#include <stdio.h>
/*
* CSAPP exercise 2.64
* */
/*
* 当所有奇数位为 1, 返回 1
* 假设 w 为 32
* */