Recent Entries 4
- snippet critical 112d agoHow to convert from []byte to int in Go ProgrammingI need to create a client-server example over TCP. In the client side I read 2 numbers and I send them to the server. The problem I faced is that I can't convert from `[]byte` to `int`, because the communication accept only data of type `[]byte`. Is there any way to convert `[]byte` to `int` or I can send `int` to the server? Some sample code will be really appreciated. Thanks.
- snippet critical 112d agoConvert a string representation of a hex dump to a byte array using Java?I am looking for a way to convert a long string (from a dump), that represents hex values into a byte array. I couldn't have phrased it better than the person that posted the same question here. But to keep it original, I'll phrase it my own way: suppose I have a string `"00A0BF"` that I would like interpreted as the ``` byte[] {0x00,0xA0,0xBf} ``` what should I do? I am a Java novice and ended up using `BigInteger` and watching out for leading hex zeros. But I think it is ugly and I am sure I am missing something simple.
- pattern critical 112d ago"TypeError: a bytes-like object is required, not 'str'" when handling file content in Python 3I've very recently migrated to Python 3.5. This code was working properly in Python 2.7: `with open(fname, 'rb') as f: lines = [x.strip() for x in f.readlines()] for line in lines: tmp = line.strip().lower() if 'some-pattern' in tmp: continue # ... code ` But in 3.5, on the `if 'some-pattern' in tmp: continue` line, I get an error which says: `TypeError: a bytes-like object is required, not 'str' ` I was unable to fix the problem using `.decode()` on either side of the `in`, nor could I fix it using ` if tmp.find('some-pattern') != -1: continue ` What is wrong, and how do I fix it?
- pattern critical 112d ago"TypeError: a bytes-like object is required, not 'str'" when handling file content in Python 3I've very recently migrated to Python 3.5. This code was working properly in Python 2.7: `with open(fname, 'rb') as f: lines = [x.strip() for x in f.readlines()] for line in lines: tmp = line.strip().lower() if 'some-pattern' in tmp: continue # ... code ` But in 3.5, on the `if 'some-pattern' in tmp: continue` line, I get an error which says: `TypeError: a bytes-like object is required, not 'str' ` I was unable to fix the problem using `.decode()` on either side of the `in`, nor could I fix it using ` if tmp.find('some-pattern') != -1: continue ` What is wrong, and how do I fix it?