Tutorial by Examples: binary

To instantiate Foldable you need to provide a definition for at least foldMap or foldr. data Tree a = Leaf | Node (Tree a) a (Tree a) instance Foldable Tree where foldMap f Leaf = mempty foldMap f (Node l x r) = foldMap f l `mappend` f x `mappend` foldMap f r fo...
Implementations of traverse usually look like an implementation of fmap lifted into an Applicative context. data Tree a = Leaf | Node (Tree a) a (Tree a) instance Traversable Tree where traverse f Leaf = pure Leaf traverse f (Node l x r) = Node <$> traverse f l <*...
git bisect allows you to find which commit introduced a bug using a binary search. Start by bisecting a session by providing two commit references: a good commit before the bug, and a bad commit after the bug. Generally, the bad commit is HEAD. # start the git bisect session $ git bisect start ...
Binary data types of either fixed length or variable length. Syntax: BINARY [ ( n_bytes ) ] VARBINARY [ ( n_bytes | max ) ] n_bytes can be any number from 1 to 8000 bytes. max indicates that the maximum storage space is 2^31-1. Examples: SELECT CAST(12345 AS BINARY(10)) -- 0x0000000000000000...
Standard Haskell allows you to write integer literals in decimal (without any prefix), hexadecimal (preceded by 0x or 0X), and octal (preceded by 0o or 0O). The BinaryLiterals extension adds the option of binary (preceded by 0b or 0B). 0b1111 == 15 -- evaluates to: True
C# has several operators that can be combined with an = sign to evaluate the result of the operator and then assign the result to the original variable. Example: x += y is the same as x = x + y Assignment operators: += -= *= /= %= &= |= ^= <<= >>=
Git is pretty good at identifying binary files, but you can explicitly specify which files are binary. Create a .gitattributes file in the project root containing: *.png binary binary is a built-in macro attribute equivalent to -diff -merge -text.
The 0b prefix can be used to represent Binary literals. Binary literals allow constructing numbers from zeroes and ones, which makes seeing which bits are set in the binary representation of a number much easier. This can be useful for working with binary flags. The following are equivalent ways o...
A hexadecimal number is a value in base-16. There are 16 digits, 0-9 and the letters A-F (case does not matter). A-F represent 10-16. An octal number is a value in base-8, and uses the digits 0-7. A binary number is a value in base-2, and uses the digits 0 and 1. All of these numbers result in ...
var wsHost = "http://my-sites-url.com/path/to/echo-web-socket-handler"; var ws = new WebSocket(wsHost); var buffer = new ArrayBuffer(5); // 5 byte buffer var bufferView = new DataView(buffer); bufferView.setFloat32(0, Math.PI); bufferView.setUint8(4, 127); ws.binaryType = 'arrayb...
You can diff UTF-16 encoded files (localization strings file os iOS and macOS are examples) by specifying how git should diff these files. Add the following to your ~/.gitconfig file. [diff "utf16"] textconv = "iconv -f utf-16 -t utf-8" iconv is a program to convert differe...
#include <stdlib.h> #include <stdio.h> int main(void) { result = EXIT_SUCCESS; char file_name[] = "outbut.bin"; char str[] = "This is a binary file example"; FILE * fp = fopen(file_name, "wb"); if (fp == NULL) /* If an erro...
Binary folds are basically unary folds, with an extra argument. There are 2 kinds of binary folds: Binary Left Fold - (value op ... op pack) - Expands as follows: (((Value op Pack1) op Pack2) op ...) op PackN Binary Right Fold (pack op ... op value) - Expands as follows: Pack1 op (......
To convert decimal number to binary format use base 2 Int32 Number = 15; Console.WriteLine(Convert.ToString(Number, 2)); //OUTPUT : 1111 To convert decimal number to octal format use base 8 int Number = 15; Console.WriteLine(Convert.ToString(Number, 8)); //OUTPUT : 17 To conv...
import random probability = 0.3 if random.random() < probability: print("Decision with probability 0.3") else: print("Decision with probability 0.7")
You can read an a binary file using this piece of code in all recent versions of Java: Java SE 1.4 File file = new File("path_to_the_file"); byte[] data = new byte[(int) file.length()]; DataInputStream stream = new DataInputStream(new FileInputStream(file)); stream.readFully(data); s...
You can have a dependency with a single jar or multiple jar files. With a single jar file you can add: dependencies { compile files('libs/local_dependency.jar') } It's possible to add a directory of jars to compile. dependencies { compile fileTree(dir: 'libs', include: ['*.jar']...
You can add remote dependencies in Gradle usign this structure: compile 'group:name:version' or this alternative syntax: compile group: 'xxx', name: 'xxxxx', version: 'xxxx' For example: compile 'com.android.support:appcompat-v7:24.1.0' The compile 'com.android.support:appcompat-v7:24.1....
BigInteger supports the binary logic operations that are available to Number types as well. As with all operations they are implemented by calling a method. Binary Or: BigInteger val1 = new BigInteger("10"); BigInteger val2 = new BigInteger("9"); val1.or(val2); Output:...
This is a specialized field, used to store binary data. It only accepts bytes. Data is base64 serialized upon storage. As this is storing binary data, this field cannot be used in a filter. from django.db import models class MyModel(models.Model): my_binary_data = models.BinaryField() ...

Page 1 of 3