## [Solved] All binary permutations of a fixed length in C

The answer goes like this. In C, the natural way to deal with an array of [0,1] is by treating them as bits. The 2^24 permutations of 24 bits are precisely the values of unsigned int from 0 to 2^24-1. So the question essentially is how to write the code based on that data structure. … Read more

## [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] How to calculate any power of a base 2 number in Java by not using BigInteger?

I’m not sure I understand your problem completely, but if n is the binary number converted to a decimal number, then you are playing with way too large numbers. Consider the binary number as decimal. Your example would be the decimal number 4294969345. Just try to consider what 2^4294969345 would be. As an example 2^429 … 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] Write a c++ function that will prompt a user for an integer and convert it to binary and print in reverse order [duplicate]

Write a c++ function that will prompt a user for an integer and convert it to binary and print in reverse order [duplicate] solved Write a c++ function that will prompt a user for an integer and convert it to binary and print in reverse order [duplicate]

## [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] How binary numbers are evaluated for true or false? [closed]

Normally in C, any non-zero number will evaluate to true. If you want to check the value of a specific bit in your port, use the binary-AND operator &. Note: Logical AND, &&, and binary AND, &, are not the same thing. In your question, only PORTB will evaluate to false. 2 solved How binary … Read more

## [Solved] Converting decimal to binary in assembly x86

Your code could be simplified a lot (and simpler code usually means that it’s simpler to find any mistakes). Here’s an outline of an easier way of doing this (I’ll leave it up to you to implement it in x86 assembly): void to_bin_string(unsigned input) { char output[33]; // The number of binary digits needed to … 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]

## [Solved] How do I keep my rails integer from being converted to binary?

This is not binary, this is octal. In Ruby, any number starting with 0 will be treated as an octal number. You should check the Ruby number literals to learn more about this, here’s a quote: You can use a special prefix to write numbers in decimal, hexadecimal, octal or binary formats. For decimal numbers … Read more