Skip to content

Instantly share code, notes, and snippets.

@linuxaged
linuxaged / JAVA-SIHFT-BITS
Created April 21, 2012 05:14
Java shift bits
public class test {
public static void main(String[] args) {
byte[] binByte = {1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0};
int sum = 0;
for (int i = 0; i < 16;i++) {
sum += binByte[i] * Math.pow(2, binByte.length - 1 - i);
}
sum = sum & 0x0f00;
//sum >>= 12;
@linuxaged
linuxaged / gist:3244065
Created August 3, 2012 03:29
obj-c 多参数函数的写法
(方法的数据类型)函数名:(参数1数据类型)参数1的数值的名字 参数2的名字: (参数2数据类型) 参数2值的名字 …. ;
举个例子,一个方法的定义:
-(void) setKids: (NSString *)myOldestKidName secondKid: (NSString *) mySecondOldestKidName thirdKid: (NSString *) myThirdOldestKidName;
实现这个函数的时候:
@linuxaged
linuxaged / jinzhi.sh
Created August 14, 2012 13:37
进制转换
#!/bin/bash
while true
do
echo "#############################################################"
echo "# Author: netcat #"
echo "# Lable: jinzhi.sh #"
echo "# QQ: 297020555 #"
echo "# Create Date: 2011-06-17 #"
echo "# Version: v1.0 #"
echo "#############################################################"
@linuxaged
linuxaged / read_file_into_array.c
Created August 17, 2012 05:44
c read file into array
#include <stdio.h>
#include <stdlib.h>
#define DAT_MAX_LINES 20
int main(void)
{
int array[DAT_MAX_LINES][2];
int n = 0;
int i;
@linuxaged
linuxaged / c_read_file_row_by_row
Created August 17, 2012 06:46
c read file row by row
#include <stdio.h>
#define MAX_LINES 22050
int main(int argc, const char * argv[])
{
// 读声音数据
char array[MAX_LINES];
FILE *soundFile;
int n = 0;
if ((soundFile = fopen("sound.txt", "rb")) != NULL) {
while ((n < MAX_LINES) && !feof(soundFile)) {
@linuxaged
linuxaged / sound.txt
Created August 17, 2012 06:49
ultrasonic record data by matlab
-0.000823974609375000
@linuxaged
linuxaged / c-open-and-write-file
Created August 27, 2012 08:58
open file and write in c
/*
Name: Open_file_and_write.c
Date: 02/01/05
Description: Opens file by append example.
*/
#include <stdio.h>
int main()
{
FILE *file;
file = fopen("file.txt","a+"); /* apend file (add text to
@linuxaged
linuxaged / c-pointer-1
Created September 3, 2012 09:50
c pointer
/* order.c -- precedence in pointer operations */
#include <stdio.h>
int data[2] = {100, 200};
int moredata[2] = {300, 400};
int main(void)
@linuxaged
linuxaged / c_stack_grow_direct
Created September 11, 2012 01:52
c_stack_grow_direct
#include<stdio.h>
static void find_stack_direction(void);
static int stack_dir;
int main(void)
{
find_stack_direction();
if (stack_dir == 1)
puts("stack grew upward");
else
puts("stack grew downward");
@linuxaged
linuxaged / mysql-sql
Created September 18, 2012 14:13
create 10000 record table with sql in mysql
CREATE TABLE `nanjing` (
`id` int(11) DEFAULT NULL,
`name` char(255) CHARACTER SET latin1 DEFAULT NULL,
`dalei` int(11) DEFAULT NULL,
`xiaolei` int(11) DEFAULT NULL,
`hanyi` text,
`longitude` double DEFAULT NULL,
`latitude` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;