In http://www.parashift.com/c++-faq-lite/intrinsic-types.html#faq-26.6, it is wriiten that
"Another valid approach would be to define a "byte" as 9 bits, and simulate a char* by two words of memory: the first could point to the 36-bit word, the second could be a bit-offset within that word. In that case, the C++ compiler would need to ad...
On occasion, the following code works, which probably means good concept, but poor execution. Since this crashes depending on where the bits fell, this means I am butchering a step along the way. I am interested in finding an elegant way to fill bufferdata with <=4096 bytes from buffer, but admittedly, this is not it.
EDIT: the error ...
I'm looking for an innovative way to check if a number has only one on bit in a signed int.
I am well aware that I can simply do a loop with a counter, some modular division, and a bit shift. But I'm curious if there is a better way since we are only looking for ONE bit to be on.
bool HasOnlyOneBit (int numb)
{
//return true if num...
Hi All,
Trying to solve what should be a simple problem. Got a list of Bytes, want to convert it at the end of a function to an array of bytes.
final List<Byte> pdu = new ArrayList<Byte>();
....
return pdu.toArray(new byte[pdu.size()]);;
compiler doesn't like syntax on my toArray. How to fix this?
...
How about a Nibble etc.
...
I have a problem. When I run my program, it comes up with an error, specifically the CS1023 error. I guess it's because I have a declaration inside a statement, but I don't know how else to write the code. Sometimes C# annoys me, because in C++ I could get away with similar things... anyway, here's the code. I would appreciate it if som...
How can I convert an int to a byte* at a certain index in a byte*?
Ideally I would like to have something like:
unsafe{
byte* igm=stackalloc byte[8];
igm[4]=4283;
}
It would set the first part of the bit to igm[4] and the rest into igm[5].
Edit: I realize there may be a lot of possible ways to handle this, i am looking for...
Can I use bool* in any kind of meaningful way. How would I convert bool* to a byte for instance, or store bool* in a byte
My goal is to manage my own memory in a project of mine, the specifics aren't important, just something id like to do. Now I would like to be able to store my own variables, and i happen to need to store a boolean va...
Hi all,
i need to convert a string from a text field to bytes. How can i do that?
Reason: The text on the textbox will be sent by SMS to the client, and I've limited
the text to 160chars but if i put special chars like @€£‰¶÷‰‰€£@ it will be larger than
256 bytes (that's the size of an sms).
So i need to remove from 256 the converted ...
Hi all,
I have an array of unsigned chars. Basically I have an array of bits.
I know that the first 16 bits corresponds to an unsigned integer and I retrieve its value using (u16)(*(buffer+ 1) << 8 | *abcBuffer)
Then comes a data type called u30 which is described as follows:
u30 - variable length encoded 30-bit unsigned integer va...
I'm writing a program that will parse an Apache log file periodically to log it's visitors, bandwidth usage, etc..
The problem is, I don't want to open the log and parse data I've already parsed. For example:
line1
line2
line3
If I parse that file, I'll save all the lines then save that offset. That way, when I parse it again, I get:...
In .NET, I can use Encoding.UTF8.GetString(string str) or any other flavor of Encoding, to get the string representation of a byte array. Does Cocoa contain similar functionality out-of-the-box, or do I need to write some stuff to make the conversions myself?
...
Hello,
I am trying to write a decoder for a very simple type of encryption. Numbers from 0-255 are entered via Scanner, the bits are inverted, and then converted to a character and printed.
For example, the number 178 should convert to the letter "M".
178 is 10110010.
Inverting all of the bits should give 01001101, which is 77 or ...
Does the byte[] array size reflects the same size of bytes to be transmitted if I need to transmit the file via a webservice?
E.G:
byte[] testarray = new byte[100000]
means that its size if transmitted will be approx 100,000 bytes (100kB)?
thanks
...
Hello,
I have some questions about editing files with c#.
I have managed to read a file into a byte[]. How can I get the ASCII code of each byte and show it in the text area of my form?
Also, how can I change the bytes and then write them back into a file?
For example:
I have a file and I know the first three bytes are letters. How ...
Hi.
Is it possible to read a single byte via asio::read?
I'm getting a single byte response and it seems wasteful to use the current buffering code:
//Read the 1 byte reply
char buffer[1];
size_t bytesRead = asio::read(s, asio::buffer(buffer, 1));
if(bytesRead < 1) return false;
Thanks.
...
I want to get an array of bytes (Array[Byte]) from somewhere (read from file, from socket, etc) and then provide a efficient way to pull bits out of it (e.g. provide a function to extract a 32-bit integer from offset N in array). I would then like to wrap the byte array (hiding it) providing functions to pull bits out from the array (pro...
in java i can cast number to byte
for example
System.err.println((byte)13020);
the result will be
-36
how can i do the same in php ?
...
Hi,
If I am creating realtively large structure how can I calculate the bytes it occupies in memory. We can do it manually , but if the struct is large enough then how to do it? Is there some code chunk or Application?
...
Was recently reviewing some Java Swing code and saw this:
byte[] fooReference;
String getFoo() {
returns new String(fooReference);
}
void setFoo(String foo) {
this.fooReference = foo.getBytes();
}
The above can be useful to save on your memory foot print or so I'm told.
Is this overkill is anyone else encapsulating their St...