# Questions tagged [binary]

10128 questions

3

votes

1

answer

16

Views

### Is there a way to convert binary data into a data type that will allow ActiveStorage to attach it as an image to my User model

I am hitting an api to get an image that they have stored and use it as the profile pic for our application's users. I'm using Ruby on Rails and ActiveStorage with AWS to attach and store the image. What they send back is this:
{'status'=>'shared', 'values'=>[{'$objectType'=>'BinaryData', 'data'=>'/...

1

votes

2

answer

740

Views

### How to print A binary tree?

how can i send (node.data) from SortTree Class to TreePrinter then used to print A Tree .
import javax.swing.tree.TreeNode;
public class SortTree {
static Node root;
TreePrinter type =new TreePrinter();
class Node{
int data;
Node left, right;
Node(int d) {
data = d;
left = null;
right = null;
}
}
N...

1

votes

2

answer

386

Views

### Smallest element in tree that is bigger than x

If I want to find the smallest element in a tree that is bigger than an element x, would this be a correct way to do it?
class Node {
int data;
Node left, right;
}
Node root;
public Integer successorOf(int x) {
return successorOf(x, root);
}
private Integer successorOf(int x, Node n) {
if (n == nul...

1

votes

1

answer

116

Views

### Is it necessary to convert a data to binary set to calculate similarity (jaccard index)?

I need to calculate jaccard similarity to dataframe below:
df = data.frame(
a=c('1', '1', '1', '1', '2', '2', '2', '3', '3', '4', '4', '4', '4'),
b=c('100', '101', '111', '25841', '111', '101', '106', '101', '108', '100', '30256', '108', '112'))
Is necessary i convert data to binary set? How do thi...

1

votes

1

answer

56

Views

### Binary Node Tree, wrong father and sons

I'm having a hard time printing the following tree:
----------t1:----------
tree:(((1),2,(3)),4,((5),6,(7,(8))))
----------t2:----------
tree:(((1),2,((3),4)),5,(6,(7,(8))))
----------t3:----------
tree:((1),2,(3,(4,(5,(6,(7,(8)))))))
----------t4:----------
tree:((((((((1),2),3),4),5),6),7)...

1

votes

1

answer

18

Views

### Designing data structure which can decrease range in lgn

I was asked in an exercise to design a data structure which can handle the following methods in logarithmic time complexity (lgn):
Insert(x): Inserts x to the data structure
Find(x): Finds if x exists in the data structre
Decrease(x, y): Adds negative value y (y

1

votes

0

answer

111

Views

### How can I detect an overflow in binary multiplication?

I am a little desperate on how to detect an overflow when multiplying two 8-bit signed binary numbers? The result should also have 8-bit.
I multiply them in a microprogram using shift and add instructions. My algorithm works like this in pseudocode for multiplying binary numbers a * b, in addition I...

1

votes

1

answer

63

Views

### Need help on BDDs graphs

I am reimplementing (for fun, a bit of work and a severe case of NIH) a ROBDD library. I would like to have a few 'reference' graphs built by other libraries to compare results [*]
E.g., given the variable order x1 < y1 < x2 < y2, what would be the graph obtained for
(x1 y1) /\ not (x2 y2) /\ (x2...

16

votes

4

answer

31.1k

Views

### Fortran unformatted file format

I don't understand the format of unformatted files in fortran.
For example:
open (3,file=filename,form='unformatted',access='sequential')
write(3) matrix(i,:)
outputs a column of a matrix into a file. I've discovered that it pads the file with 4 bytes on either end, however I don't really understan...

1

votes

0

answer

44

Views

### HTML 5 audio tag, what is the expected encoding?

Can I specify the encoding of the file being received, is it only binary? Can I tell it it's expecting base64 etc?
Example use case :
If your browser doesn't support the 'audio' element, it will display the content here between the opening and closing tags.

1

votes

1

answer

191

Views

### Reading binary file with batch size using boost serialization

I am trying to serialize the class with boost's binary serializer, and loading the binary data with batch size.
I am able to fetch the first 5 records out of 10, and the process is crashing while I am trying to read an another 5 records by re-opening the file and re-setting the file read pointer to...

1

votes

1

answer

275

Views

### convert non balanced binary search tree to red black tree

Is it possible to convert a non balanced BST (the size of the tree is n and the height is h) to RBT in time complexirty of O(n) and space complexity of O(h)?

1

votes

0

answer

24

Views

### in given number x , can i check if x exist in the array with time complexity of log(n)+log(m)?

Given a two-dimensional array sorted in size of NxM so that:
The rows are sorted from left to right - from large to small.
The cols are sorted from up to down - from large to small.
in given number x , can i check if x exist in the array with time complexity of
log(n)+log(m)
?

1

votes

0

answer

53

Views

### Percentage sign binary operator in ggplot R

I used percentage signs in the column names of a data frame. So far, I haven't encountered any disadvantages by doing so.
Now I would like to create a ggplot with my data and get the following error due to the use of percentage signs:
Error in stat_boxplot(geom = 'errorbar') + geom_boxplot() :
non-...

1

votes

1

answer

48

Views

### How to compare the shape of one SortedSet to another in C#

I'm trying to compare the shape (by shape, I mean the shape of the binary tree) of one SortedSet at a certain index of a List of SortedSets against all the rest of the SortedSets in that same List. I've tried to look up ways to compare Binary Trees, but I don't know how to do it with SortedSets inst...

1

votes

1

answer

56

Views

### Writing data from a structure to a file in c#

So I am currently attempting to write data from a structure to a binary file and am not having a ton of luck, I was just wondering if anyone could point me in the right direction of what I may need to implement as most of what I've tried and researched has been unsuccessful. Below is very basic skel...

1

votes

0

answer

38

Views

### Python3.4 packing and format type with struct

I have a binary file which I am trying to recreate by writing data to a new file. The data in it should be stored as 32-bit (4-byte) twos- complement binary integers or as ASCII characters. The first 4 bytes should represent the integer 0, then the next 4 should be the integer 4, the next 4 should b...

1

votes

0

answer

72

Views

### Why are the values incorrect when parsing binary data using python ctype structures?

This binary data is being parsed via a python parser file containing ctype structures. Unfortunately, it is not returning the proper values. Most likely this is because I am not 100% sure how to interpret this data.
This spec outlines how the binary data is organized. I am not 100% sure how to inter...

1

votes

2

answer

358

Views

### Retrieve data from .rec binary file

The question may be naive, but answers could help me.
A measurement is recorded in binary format, with a header that contains all information about the data and the data itself (i.e. a series of doubles).
The measurement data can be exported in csv format from the application, but it takes ages....

1

votes

2

answer

52

Views

### Finding kthSmallestElement in the BST

I am trying to solve the following question from LeetCode:
https://leetcode.com/problems/kth-smallest-element-in-a-bst/description/
The aim is, given a BST, we have to find out the Kth-smallest element in it and return its value.
I could come up with a O(n) time and space solution myself. But anoth...

1

votes

1

answer

40

Views

### Viewing image file bytes

Not looking for help accomplishing anything specific. Looking to understand what is happening. Can anyone explain or point to a source to help me understand? Thank you.
I have a JPEG containing 1 pixel with a (0,0,0) RGB value.
Opening in a text editor shows 631 hexadecimal pairs. The 1st pair is 'f...

1

votes

0

answer

69

Views

### Binary Tree size function python

I'm a beginner of Python and data structure, I have a problem with designing the binary tree size method, my code and my error are as follows
class BinaryTree:
def get_left(self):
return self.left
def get_right(self):
return self.right
def set_data(self, data):
self.data = data
def get_data(self):
r...

1

votes

0

answer

64

Views

### My binary search on java doesn't count or print the right index values after the search

I am programming a class that when called upon, would search for a specific number using binary search. The program would also print the number of times it searched for a said number, and return the index value. Unfortunately, the index value always returns me a -1, which is the number I set it as w...

1

votes

2

answer

52

Views

### Binary search with process output

Expected output :
If the key is below the mid point
Data : [1, 4, 6, 13, 14, 23, 30, 45, 58, 67, 76, 89, 99]
Input key : 6
Binary Search :
1 step index - 0 : 1, not found !
2 step index - 1 : 4, not found !
3 step index - 2 : 6, founded !!
If the key is greater than mid point
Data : [1, 4, 6, 13, 14...

1

votes

0

answer

88

Views

### How can I send resource to API through Content-Type: application/octet-stream php

I am trying to reproduce this POST https://www.screencast.com/t/OUE1StfLfyP7 in php but I couldn't archive that it works correctly because after downloading the image is not possible to open it
$url = 'https://internal-api-staging-lb.interact.io/v2/contacts/X/documents/fr_FR9.gif';
$data = array('fi...

1

votes

0

answer

21

Views

### Pivoting a large table

I have a very messy table with two kinds of columns, a 'start' point and a 'end' point. Wherever the start point occurs, there is a 1, and wherever the end point occurs, there is a 1. All other cells are filled with zeros, so each row only contains two 1 values. Here's a general idea of what it look...

1

votes

0

answer

381

Views

### Hierarchical logistic regression

I am trying to predict depression by using two quantitative variables and their interaction. However, before I want to see how much variance they explain, I want to control for a few variables.
My plan was to build a logistic regression model:
Depression = Covariates + IV1 + IV2 + IV1:IV2
Unfortunat...

1

votes

3

answer

245

Views

### error: bad operand types for binary operator '=='

Just wanted to do a task in my Book but I don't get why this is wrong.It should say that negative Numbers aren't positive and positive aren0t negative with a Boolean.
This is my Code:
import javax.swing.JOptionPane;
public class Zahlentest {
public static void main(String[] args) {
String eingabe;
c...

1

votes

1

answer

27

Views

### Java BST program crashes when I call self implemented search method

I have been trying to figure out why my program keeps crashing. When I compile in eclipse everything runs smoothly until I select the 'search' option in my menu driven BST. I keep getting the error java.lang.NullPointerExcpetion. Part of me feels as if my add method is not working properly when crea...

1

votes

1

answer

238

Views

### Binary Tree Visualization - circular tree? (QT)

I was wondering if anyone has any advice on implementing an algorithm for creating a circular 'phylogenetic' type:
graphics scene for a binary tree in QT? Something like this:
except with the word labels replaced with buttons.
I'm currently using QT Elastic Nodes as a template, and have managed to...

1

votes

0

answer

36

Views

### How to send & handle image properly between ruby & node.js image-size

Try to send file (image) over http request from ruby client (using RestClient) to node.js server
Client (Ruby) code
Image file is a tempfile that read to payload parameter as binary like so:
tf = open('http://via.placeholder.com/220x220')
tf.binmode
response = JSON.parse(
RestClient::Resource.new(ur...

1

votes

1

answer

425

Views

### Print a binary search tree as a single string

There's a practice problem that I've been working on that's been confusing me.
Define a function treeLevelOrder which satisfies the following claim:
If Q is a binary search tree of integers, then treeLevelOrder(Q) is the String representation of the contents of Q according to their level in the tree...

1

votes

0

answer

70

Views

### Binary Search Output Issue in Inventory Program c++

I am having issues with binary search function within my homework (I am completely done with it except for this one issue).
The program allows a user to manage the inventory of a small store that sells various products of any type. It will first read the inventory from a text file named “inventory...

1

votes

2

answer

20

Views

### Java BNST toString

So I'm working on a school project of an implementation a binary search tree. I have to create a toString method that returns all nodes as string. I was able to do it as a void but I'm having a hard time figuring out how to return a String of all the nodes.
Heres my working void toString function....

1

votes

1

answer

176

Views

### Binary search not working for all test cases

I'm trying to implement a recursive binary search in Java, however, it it not working for all test cases. I am doing a Hacker rank challenge, and it is not showing me the test cases I've missed. When I test it with my own cases, it always tests successfully. I don't know what I'm missing.
import jav...

1

votes

1

answer

136

Views

### Adding, Subtracting, Dividing, and Multiplying two binary numbers stored in boolean arrays

I need help with making a Binary calculator. I am trying to add, subtract, divide, and multiply two binary numbers that are stored as a boolean[] array in java. I'm pretty stuck so some help would be greatly appreciated! thanks!
private static boolean[] multiply(boolean[] bits1, boolean[] bits2) {
/...

1

votes

1

answer

403

Views

### Iterative binary search with only two comparisons?

Adjust the iterative binary search code so that it uses only two comparisons instead of three (in
the main while loop). *Note: The three comparisons are in the while loop, and two if statements
within the loop.
#include
int ItBinarySearch(int arr[], int len, int target) {
int first = 0;
int last =...

1

votes

0

answer

245

Views

### Dynamically constructing a binary tree using “Node” structure in python

I’m trying to convert a mathematical expression into a binary tree structure using the “Node” type in zss library. I’m using this particular “Node” type because I want to compute the tree edit distance using a function in the same library.
Mathematical expressions can be in different for...

1

votes

1

answer

77

Views

### Tricky Segmentation faults with BST recursion in C

I'm trying to add strings to a Binary Search Tree using a recursive insert method (the usual for BSTs, IIRC) so I can later print them out using recursion as well.
Trouble is, I've been getting a segmentation faults I don't really understand. Related code follows (this block of code is from my main...

1

votes

0

answer

112

Views

### C - printing to a file results in garbage characters but printing to stdout doesn't?

I made this thread a few hours ago:
Tricky Segmentation faults with BST recursion in C
Managed to figure it out after hours of trying. I've run into another snag, however. It's a weird one. Relevant code for perspective:
extern char *optarg;
extern int optind;
int c, err = 0;
char currentLine[STRING...