由买买提看人间百态

topics

全部话题 - 话题: 0xff
1 (共1页)
w**********6
发帖数: 800
1
我写的菜鸟code,请二爷看看,然后能否提示一下,如果不保证输入是0-9的话怎么搞
?感觉还是这么搞的话貌似不靠谱,大小写字母加一块儿太多了。。。
void rmdup(int a[],int n)
{
int b[10] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};

for(int i=0;i {
b[a[i]] = a[i];
}

//print it out

for(int i=0;i {
if(b[i]!=0xFF)
{
printf("%d ",b[i]);
}
}

}
w*s
发帖数: 7227
2
hi, i'm new to this, many thanks for help !
trying to send a query packet out,
size 1454 bytes, 1st word 0xfffffffb, 2nd 0xffffffff, 3rd 0x392
the correct packet sent from c code is captured in wireshark in the picture,
but got this,
socket.error: [Errno 10051] A socket operation was attempted to an
unreachable network
The code is like this,
def send_pnp_query():
print "... send query ..."
msg = bytearray(1454)
#ptr = PNP(msg)
msg[0] = 0xfb
msg[1] = 0xff
msg[2] = 0xff
... 阅读全帖
j******n
发帖数: 108
3
来自主题: Java版 - byte[] to int[]
很简单的一个问题,把 byte[] 转换成相应的 int[]
我写了一个循环,每次转换 4byte
因为需要转换的数量可能比较大,有几十万的int
我测了一下时间,还是不大能满足我的要求
请问,还有没有比较优化的方法么?比如类似 c 里面的 memcp
4byte 到 int 的转换如下:
int x = ((buf[start] & 0xFF) << 24)
| ((buf[start+1] & 0xFF) << 16)
| ((buf[start+2] & 0xFF) << 8)
| (buf[start+3] & 0xFF);
还是说,大概只能达到这个水平,很难再优化了?
非常感谢!
c*****t
发帖数: 1879
4
来自主题: Programming版 - 有没有现成的模拟fread的bufferRead()?
先把整个文件读进一个大的 char* buffer 。然后
for (...)
{
// for portable code do... change shift for different endian
x = ((buffer[i] & 0xff) << 24) |
((buffer[i + 1] & 0xff) << 16) |
((buffer[i + 2] & 0xff) << 8) |
(buffer[i + 3] & 0xff);
// otherwise can use the following
// occasioanlly may need to consider alignment
x = *(int*)&buffer[i];
i += 4;
// likewise for long etc
...
}
c***2
发帖数: 838
5
#1: In C, please write code to determine the longest consecutive bit string
(1 or 0) in an array of bytes.
For example,
char string[] = { 0xff, 0xa0, 0x00, 0x01, 0xff, 0xff, 0xaa };
(longest 1's)=18 (longest 0's)=20
So longest consecutive bit string=20
j***y
发帖数: 2074
6
在193~194页,书里谈到了一个下面的问题:
---
Signedness of char. In C and C++, it is not specified whether the char data type is signed or unsigned. This can lead to trouble when combining chars and ints, such as in code that calls the int-valued routine getchar(). If you say
? char c; /* should be int */
? c = getchar();
the value of c will be between 0 and 255 if char is unsigned, and between -128 and 127 if char is signed, for the almost universal configuration of 8-bit characters on a two's complement machin... 阅读全帖
t****e
发帖数: 32
7
您要开发还是只颜色识别?
其实点QQ截图,随鼠标移动,图像框下方就有RGB color, maxthon也有snap tool, 显
示HEX color, photoshop可以的,但如果只是查颜色似乎没有必要用ps这么大的软件。
如果是开发,取决于你用哪一种语言,以java为例,用getRGB method获取:
int rgb = image.getRGB(x,y,w,h.....);
int red = (rgb>>16)&0xff;
int green = (rgb>>8)&0xff;
int blue = (rgb)&0xff;
hope this helps.
g**********y
发帖数: 14569
8
来自主题: JobHunting版 - 这个facebook puzzle样题怎么做?
这个题不好写的是状态保存和转换。
最多5个peg, 8个disc, 所以可以用long(64-bit)来保存状态,转换需要位操作。
这是我的写法,欢迎改进:
public class KPeg {
public void move(int N, int K, int[] begin, int[] end) {
long s0 = stateToLong(begin);
long sn = stateToLong(end);

ArrayList visited = new ArrayList();
visited.add(new Node(s0, 0, 0, -1));

Deque dq = new ArrayDeque();
dq.add(0);

while (!dq.isEmpty()) {
int current = dq.remov... 阅读全帖
s**x
发帖数: 7506
9
来自主题: JobHunting版 - LinkedIn 面经
http://stuff.mit.edu/afs/sipb/contrib/linux/arch/microblaze/lib
/*
* Copyright (C) 2008-2009 Michal Simek
* Copyright (C) 2008-2009 PetaLogix
* Copyright (C) 2007 John Williams
*
* Reasonably optimised generic C-code for memcpy on Microblaze
* This is generic C code to do efficient, alignment-aware memmove.
*
* It is based on demo code originally Copyright 2001 by Intel Corp, taken
from
* http://www.embedded.com/showArticle.jhtml?articleID=19205567
*
* Attempts were made, unsu... 阅读全帖
a*****a
发帖数: 438
10
ok, that makes sense.
so i guess they store this read/unread information like this:
0xff, 0x00, 0xff, 0x1 (ie. 255 read, 255 unread)
c******e
发帖数: 545
11
来自主题: Programming版 - C 语言,数字变字符,有点难度
除了别人的解法
1.用指针
short int num = 532;
char * c_ptr = (char*)(&num);
然后可以用c_ptr访问num的每个字节。little endian系统里,c_ptr[0]是LSB
2.逻辑运算
short int num = 532;
char LSB = (char)(num & 0xFF);
char MSB = (char)((num >> 8) & 0xFF);
这个不是数字变字符
s********k
发帖数: 6180
12
来自主题: JobHunting版 - 请问一个little endian 系统的问题
系统是little endian, 定义一个Usigned int 32, 然后bit shift >>1.这个操作还
是除法(/2)吧,而不是把LSB往MSB移,从而导致变成(*2)?
同样 如果做强制类型转换,比如定义一个Usigned int32 a = 0x00ff
那么(uint16) a = 0xff?而不是0x00吧
有点糊涂,大侠指教下
m*********2
发帖数: 701
13
wow, good point.
yea, i think what the author saying is:
EOF == -1
0xFF == 255.
that's why you want to use int.
it's large enough to differentiate whether it's -1 or 255.
the short answer is:
getchar() returns int.
and c is int.
so, you are comparing integers, NOT char.

data type is signed or unsigned. This can lead to trouble when combining
chars and ints, such as in code that calls the int-valued routine
getchar(). If you say
between -128 and 127 if char is signed, for the almost universal
co... 阅读全帖
j***y
发帖数: 2074
14

But this is not true when the system is using sign-extension in casting char
to int.
With sign-extension, 0xFF is the same as -1, isn't it?
c****p
发帖数: 6474
15
没有。。。。。。
getchar()返回值是int,所以EOF返回-1,0xff返回255。
所以没问题。

char
w*******s
发帖数: 138
16
书上说的是对的
EOF 是 (int)-1
unsigned char c = EOF;
c是0xff
c == EOF // false
(int)c == 255 // 不管是不是sign-extension都一样

char
j***y
发帖数: 2074
17
谢谢大家啊,我刚才不自觉地就把getchar()的返回值认为是char了。真是糊涂。
顺便问一下,一个文本文件中可以包含0xFF这样的字节吗(不是文件末尾)?
m*********2
发帖数: 701
18
yea....
EOF is a special character, and is platform-dependent.
so, it doesn't have to be -1 or 0xFF
and, welcome to a programmer's life.
You are always f*cking working WITH other people's bug (in design or
implement)
p*****2
发帖数: 21240
19
来自主题: JobHunting版 - G家电面被拒,请帮助分析原因

256是0xFF+1
h*****f
发帖数: 248
20
来自主题: JobHunting版 - 如何判断char的赋值有没有溢出
Hmm...a char can hold 0x0-0xFF. 128=0x80...so no overflow..
I guess the question is to detect whether the input occupies more than 1
byte?
You probably could *if* it were foo(char*) or foo(char&).
d**********x
发帖数: 4083
21
来自主题: JobHunting版 - 一些位运算的题目
只能使用 ! ~ & ^ | + << >>
可以用 =,可定义局部变量,字长32bit,右移是算数右移,不许cast
常量只能在0~0xff之间。实际上一般面试不会有这个约束,就忽略吧
1. int isAsciiDigit(int x);
如果x是'0'~'9',返回1,否则返回0
2.int anyEvenBit(int x);
如果任何偶数位上有1返回1 (1 --> 1, 2 --> 0)
3.int copyLSB(int x);
如果x & 1,则返回0xffffffff,否则返回0
4.int leastBitPos(int x);
5.int divpwr2(int x, int n);
输出 x / pow(2, n);,n非负。
6.int conditional(int x, int y, int z);
相当于x ? y : z
7.int isNonNegative(int x);
非负数返回1
8.int isGreater(int x, int y);
如果x > y,返回1
9.int absVal(int x);
返回x的绝对值
10.int isP... 阅读全帖
j*****y
发帖数: 1071
22
来自主题: JobHunting版 - BB onsite惨败而归 血的教训!
明白了,
-1 convert 到 unsinged char 是 0xff
memset(a, -1, 16)就把每个 bit变成了 1
这样的话 a[] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}
而 0xffffffff 换成 int 就是 -1
j*****y
发帖数: 1071
23
来自主题: JobHunting版 - BB onsite惨败而归 血的教训!
明白了,
-1 convert 到 unsinged char 是 0xff
memset(a, -1, 16)就把每个 bit变成了 1
这样的话 a[] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}
而 0xffffffff 换成 int 就是 -1
l******d
发帖数: 530
24
手工算是忘了,这个行不,在低位优先的机器上:
char t[2];
t[0] = 0xD8;
t[1] = 0xFF;
int16_t i = *(int16_t*)t;
printf("%d\n", i);
y*****n
发帖数: 11251
25
来自主题: Indiana版 - 秋假有人去Columbus吗



Invalid Request
Cannot identify unique input location, Request \"Columbus\"
has 2 matches


d*h
发帖数: 2347
26
来自主题: WaterWorld版 - 借人气问个c语言的问题,求救
绝大多数是,但不一定。有的系统里面可能0xFF是NULL。
d**********o
发帖数: 1321
27
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
RTOS作业:2514
The purpose of this assignment is to give you more experience using the AVR
ports, and to add some I/O devices that might become useful later for our
RTOS.
You are to use one of the provided keypads to implement a “digital lock.”
Your program should allow the user to enter a four digit code from the
keypad, and if the code that is input matches the one included in your
program, the “lock” should open. In this case, the lock opening will be
represented by the lighting of an LED.
As th... 阅读全帖
d**********o
发帖数: 1321
28
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
RTOS作业:2514
The purpose of this assignment is to give you more experience using the AVR
ports, and to add some I/O devices that might become useful later for our
RTOS.
You are to use one of the provided keypads to implement a “digital lock.”
Your program should allow the user to enter a four digit code from the
keypad, and if the code that is input matches the one included in your
program, the “lock” should open. In this case, the lock opening will be
represented by the lighting of an LED.
As th... 阅读全帖
x*z
发帖数: 1010
29
来自主题: Hardware版 - 绿盘一个月load cycle count到了93677
我老用idle3怎么设也设不到300,只好设了个0xff了事,
另外为什么不能disable?
c***r
发帖数: 4631
30
来自主题: Java版 - 问个很简单的问题?
The problem maybe "endian", java use "big-endian" and C on intel CPU will use
"little endian". So the data is confusing. And you may use code below to solve
this problem
float readFloatLittleEndian( )
{
int accum = 0;
for ( int shiftBy = 0; shiftBy < 32; shiftBy+ =8 )
{
accum |= (readByte () & 0xff) << shiftBy;
} return Float.intBitsToFloat (accum);
}
I got it from http://mindprod.com/jglo
z********i
发帖数: 60
31
来自主题: Java版 - ask a question about C
读数据从文件中,
input=fopen(filename,"rb");
while ( (c=fgetc(input)) != EOF )
{
}
可是数据中有0xff, 255(int)好像这个被当成eof了,请问有什末办法读出来吗?
g*******e
发帖数: 14
32
来自主题: Java版 - ask a question about C
what is the type of c? int or char?
if char, you get into trouble because
-1 is same as 0xff in char.
Q**g
发帖数: 183
33
来自主题: Java版 - ask a question about C
what's the data type of variable c? if it's int, the code should be fine.
if it's char, you may get a problem coz you can not differentiate EOF
and 0xff. the following paragraph is extracted from GNU C library:
These functions return an int or wint_t value (for narrow and wide stream
functions respectively) that is either a character of input, or the special
value EOF/WEOF (usually -1). For the narrow stream functions it is
important to store the result of these functions in a variable of type i
r****t
发帖数: 10904
34
来自主题: Linux版 - polipo logLevel 不管用?
这里有用 polipo 的高人没?我这配了个 polipo 工作正常,但是设
logLevel = 0xFF
最大值以后,还是没有任何 logs 出来,除了以前一直有的 "Established listening
socket on ..." 这一句以外。
用的是 1.0.4.1-1.1 on debian
u*********r
发帖数: 2735
35
#include
int main()
{
int n = 173033810;
do
{
putchar( n & 0xff );
n >>= 8;
} while (n);
}
I*******e
发帖数: 1879
36
来自主题: Programming版 - 问一个在C里面转换十六进制的问题
我现在有一串0和1组成的位流,现在要每隔八位换成十六进制输出
十六进制是 unsign char, 比如0xFF占一个字节,C里面有现成的函数吗?
那位大侠知道细节,好多年不用C了,我都忘记这些底层的东西了,谢谢
b******n
发帖数: 592
37
来自主题: Programming版 - pointer overflow
has anyone experienced pointer overflow in C++. I have a
void * ptr
what I am doing in C++ is :
ptr = reinterpret_cast(ptr)[size]
ugly, but I don't know how to do it prettier.
and the ptr overflowed.
0x7f7ea69f443d is base address
477856 is size
the result is:
0xa69f4440
I found it is very diffult to use raw pointer in C++. For example, if I want
to align the address, I can't do ptr &= ~0xff, something like this.
any suggestion?
a****l
发帖数: 8211
38
unsigned int_8 a; //8bit unsigned integer
signed int_16 b; //16bit signed integer
a=0xFF;
b=a;
What's the value of b? The question is, which happens first, unsigned->
signed or 8bit->16bit?
1 (共1页)