[Solved] How many possibilities on a binary? [closed]

I assume you are thinking of binary rather than hexadecimal? Binary is base 2 (hence either 0 or 1s) where as Hexadecimal is base 16. Assuming you are talking about binary: If you have 8 bits you have 28 possibilities. If you have 9 bits you have 29 possibilities. If you have 10 bits you … Read more

[Solved] Evaluating C binary operations

k=25; ++k; k++; k|7&12; After the first 3 lines, k is 27. In the fourth expression, the bitwise AND operator & has higher precedence than the bitwise OR operator |, so it is equivalent to 27|(7&12); Converting the values to binary gives us 11011|(00111&01100); The inner part evaluates to 00100, then 11011|00100 evaluates to 11111, … Read more

[Solved] What is this operation in C?

Assuming ICANON is a bit-mask, i.e. an integer with bits set to represent some feature, that statement will make sure those bits are not set in c_lflag. This is often called “masking off” those bits. The operation is a bitwise AND with the bitwise inverse (~ is bitwise inverse). So, if the value of c_lflag … Read more

[Solved] How do I convert ‘Single’ to binary?

The example expected value you’ve provided is just a straight binary representation of the number, however while probably not the most efficient way if you wanted to get the IEEE-754 representation of the number in binary you could use BitConverter.GetBytes as in the following example: Sub Main Dim i As Int32 = 1361294667 Console.WriteLine(ObjectAsBinary(i)) Dim … Read more

[Solved] Convert any file to binary string and from binary to file [closed]

Finally, I discovered that the problem was in the code. Just small mistake using substr func. So, the correct code is: $buffer = file_get_contents(“image.png”); $length = filesize(“image.png”); if (!$buffer || !$length) { die(“Reading error\n”); } $_buffer=””; for ($i = 0; $i < $length; $i++) { $_buffer .= sprintf(“%08b”, ord($buffer[$i])); } echo $_buffer.”<br>”; $nb = “”; … Read more

[Solved] Invert 7th bit of hex string C++ [duplicate]

#include <stdio.h> void flipme(char *buf, const char *inBuf) { int x; sscanf(inBuf, “%x”, &x); x ^= 1 << 17; sprintf(buf, “%06X”, x); } int main(void) { char buf[16]; flipme(buf, “002A05”); printf(“002A05->%s\n”, buf); flipme(buf, “ABCDEF”); printf(“ABCDEF->%s\n”, buf); } Output: 002A05->022A05 ABCDEF->A9CDEF You wrote: I tried converting hex string to integer via strtol, but that function strip … Read more

[Solved] binary tree creation in SCALA

You probably want something like this: trait BinTree[+A] case object Leaf extends BinTree[Nothing] case class Branch[+A](node: A, left: BinTree[A], right: BinTree[A]) extends BinTree[A] def buildTree[A](list: List[A]): BinTree[A] = list match { case Nil => Leaf case x :: xs => val (left, right) = xs.splitAt(xs.length/2) Branch(x, buildTree(left), buildTree(right)) } But you really need to get … Read more

[Solved] Convert IPv6 to IPV4 PHP [closed]

As Ron Maupin described, the solution is very simple $ipv6 = “8ab8:7f70::”; $ipv4 = hexdec(substr($ipv6, 0, 2)). “.” . hexdec(substr($ipv6, 2, 2)). “.” . hexdec(substr($ipv6, 5, 2)). “.” . hexdec(substr($ipv6, 7, 2)); 3 solved Convert IPv6 to IPV4 PHP [closed]