Posts

Showing posts with the label io

How to divide an Int into two Bytes in C?

Image
Clash Royale CLAN TAG #URR8PPP How to divide an Int into two Bytes in C? I am working with software embedded in minimal hardware that only supports ANSI C and has minimal versions of the standard IO libraries. I have an Int variable, two bytes in size, but I need to divide it into 2 bytes separately to be able to transmit it, and then I can, reading the two bytes, reassemble the original Int. I can think of some binary division of each byte like this: int valor = 522; // 0000 0010 0000 1010 (entero de 2 bytes) byte superior = byteSuperior(valor); // 0000 0010 byte inferior = byteInferioror(valor); // 0000 1010 ... int valorRestaurado = bytesToInteger(superior, inferior); // 522 but I do not succeed in a simple way of dividing the whole by its weight and it gives me the feeling that it should be trivial (such as with bit shifting) and I do not discover it. Actually, any solution that divides the whole into 2 bytes and reassembles it serves me well. From already thank you very much! ...

Write code that counts lines in a file under different constraints (memory, disk space, in or out of order, etc)

Write code that counts lines in a file under different constraints (memory, disk space, in or out of order, etc) In case of memory constraint, I think variation of external sort will work. What are other options. Also how to deal with disk space constraint? Does it hint towards multiple nodes and map-reduce? have you tried something, if yes show your code, so that you could get better answer – Gautam Rai Jul 15 at 14:21 Counting lines in a file doesn't require sorting anything. It also doesn't require more memory than a byte buffer for detecting a newline character, an integer (or long), and a file handle – cricket_007 Jul 15 at 14:25 ...