14,803 questions
-3
votes
0
answers
123
views
I wrote a variation of the double-to-string algorithm Ryu and I'm struggling with coverage tests [closed]
I wrote a variation of Ryu double-to-stream algorithm. My version has no meaningful impact on the code, for the purpose of this question you can read the original file.
I'm writing coverage test for ...
Advice
2
votes
5
replies
140
views
How to use space as an delimiter when the entire string is made up of spaces?
I've written a program that takes in a text then prints the binary translation of it. İts been working perfectly fine until I tried the case where entire string is just made up of spaces. As to ...
Advice
0
votes
4
replies
43
views
GNU ld binary output format
I have the following c source:
int _start(){}
which I compile as:
gcc -c -o main.o main.c -ffreestanding
then I link as:
ld -oformat binary main.o
The binary's hexdump looks as:
$ hexdump a.out
...
Best practices
0
votes
4
replies
128
views
Best way to extract a VBA Date out of a byte array and turn it back into a valid VBA Date?
I have confirmed that the following VBA code works just fine.
Dim mydate As Date
mydate = Date
Open "C:\Windows\Temp\dlctest.data" For Binary Access Write As #1
Put #1, , mydate
Close #1
...
4
votes
3
answers
193
views
How to do a simple swap of two half of a 32bit integer in c?
I am trying to figure out a code that would be able to swap the higher half and the lower half of the binary form of an integer number such as for example:
0000000 00110011 01001001 11111110 turn into ...
2
votes
3
answers
136
views
different behaviour of objcopy with binary output between Windows and Linux
I have created a simple hello.c which contains just the definition of an array:
unsigned char arr[4] = {1,2,3,77};
I have then compiled it with gcc -r in order to produce a relocatable object file. ...
0
votes
2
answers
155
views
How can I store Huffman-encoded bits into a truly compressed binary file in Java?
I'm building a Huffman compressor in Java.
I already have: The original text, the Huffman code table (Map<Character, String>), and the order of character appearance.
My current goal is to write ...
0
votes
0
answers
87
views
Is my interpretation of working with Hamming SEC code correct?
The problem: "Use Hamming's code to detect if there was an error in the following message and correct it."
m_8
m_7
m_6
m_5
m_4
m_3
m_2
m_1
c_4
c_3
c_2
c_1
1
1
1
0
1
0
1
1
0
0
0
1
My first ...
0
votes
2
answers
184
views
C program for changing binary to signed integer doesn't work properly
I have a C program that I made that is supposed to convert binary into a signed integer, but it does not give the correct result.
Here is the function of the code that converts binary numbers to ...
0
votes
1
answer
136
views
Why does my binary input 10 come out as 8? [duplicate]
I coded int num1_bin = 00000010;
However, in the debug console, it comes out as 8. Is there a mistake in my code, or a setting in C++?
I just started coding in C++ for univ.
I expected int num1_bin = ...
-1
votes
3
answers
99
views
Python Bit Shifting [closed]
Assume I have a 1 source variable (int) which is 10 bits long. Let's call it src.
I have 2 destination variables (int) which are 8 bits long namely byte1 and byte2.
MSB LSB
src ...
0
votes
2
answers
142
views
How can i convert a negative binary number to sbyte(c#)
I am messing around with c#, and i noticed something. If i were to instantiate an sbyte
with 8 bits, such as 0b_1111_1111 (-1), it throws an error, but if i were to first make a byte with it, and then ...
3
votes
1
answer
163
views
How to convert binary to utf-8 and vice-versa in R?
I want to code a shinyApp which can convert a string from binary (0 and 1, not hex) to utf-8 and vice-versa.
Example :
encode("Aé") # return "010000011100001110101001"
decode("...
2
votes
1
answer
174
views
How to Extract Individiual Frames From an .ani File?
I'm writing a Winforms app that will allow me to change my cursor. My goal is to have buttons with each having their own respective cursor as their image by converting their files into bitmaps. ...
3
votes
1
answer
230
views
How to decode and parse JEOL microscope metadata embedded in TIFF tags (binary format)?
I'm working with microscope images captured using a JEOL system, and I'm trying to decode metadata stored in the TIFF tags. The data appears to be in a binary format and when extracted (using tifffile ...
0
votes
2
answers
114
views
Efficiently Count Number of Ones at Deepest Level in Recursive Floor-Ceil Splitting of Large Binary Number
I have a number represented as a large binary string (length can be up to 1 million bits). The number is recursively split as follows:
At each step, divide the number
x into two parts:
floor(x/2) and ...
0
votes
0
answers
29
views
Detecting overflow in two’s complement multiplication by 2 – which bits need to be checked
Given a number with a width of n bits representing a signed number in two's complement, what is the minimal number of bits that need to be checked and which ones, in order to know whether there will ...
1
vote
1
answer
111
views
in kdb how do you save a 2d matrix into a binary format such that it can be read in python using numpy.fromfile or numpy.memmap?
My goal is to save a huge 2d matrix as binary in kdb q, so that my python code can import it as numpy matrix. I played with numpy.fromfile and numpy.memmap but I don't think kdb is writing it into a ...
0
votes
0
answers
40
views
Generating vertices of binary hypercube
What are the possible ways to generate all the vertices of boolean hypercube of dimension n (0 to 2^n - 1 in binary representation) using parallel programming? Also, among all the possible ways, ...
3
votes
3
answers
200
views
CURL: how to correctly convert signed char[2] to uint16_t
I have a simple CURL callback for a C websocket that needs to identify the closecode, but it gives me weird values when I shift it. I don't understand signed char binary representation.
size_t ...
0
votes
0
answers
85
views
Which of these two bitwise expressions is faster, and is there an optimized alternative?
I have two bitwise expressions and need to figure out which one is faster. Also, if there are other ways to implement the same, but in a faster way than the given expression. I am using these ...
1
vote
1
answer
99
views
Binary translator doesn't print the array in C, why is that so?
I'm making a binary translator to get back into C but the program doesn't work.
The code:
#include <stdio.h>
void clearBuffer() {
char dummy;
while (dummy != '\n') scanf("%...
-2
votes
1
answer
123
views
How can I split a 128-bit value into two 64-bit values
I'm trying to make a function that appends 2 longs into one and back again.
I used the (ac) + (ad) + (bc) + (bd) formula to combine the numbers.
I have searched for and wide (including this site) with ...
0
votes
1
answer
45
views
nginx with createObjectURL and binary png data appears to serve the file as text with utf8 encoding
We have some swagger-ui.js code generating a download link to a png image delivered from a REST API call. The download link is generated by the swagger-ui.js code:
var binaryData = [];
binaryData.push(...
0
votes
2
answers
140
views
How to convert all decimal numbers in a string to binary in java?
I needed to convert decimal numbers in a string to binary. I needed to use it for a program.
I tried this code:
static String numbers = "48, 40, 6, 82, 222, 94, 152, 46, 77";
public ...
0
votes
0
answers
94
views
NEO M9N UART config failing after attempt to increase GPS measurement rate
I am using an STM32H723 to communicate with a u-blox NEO M9N IC over the UART protocol. I have established communication with the NEO M9N GPS and received accurate positioning data at around 1 Hz. ...
0
votes
0
answers
48
views
How to write a string containing binary representation of data to file? [duplicate]
I am trying to write a binary string as binary data to file but my function seems to be having a problem with the int conversion. I am reading a text file and manipulating it which gives me a string ...
0
votes
1
answer
130
views
GNU x86 assembler wrong jump encoding?
I create a file named "test.s" with the content "jmp -2". Then I execute "as --32 -o test.o test.s" and "objdump -D test.o".
(I don't want to discuss here that ...
1
vote
0
answers
106
views
Understanding the Unexpected Behavior of Random Number Generation in a Binary-Based Function
I wrote a function in Arduino to generate random numbers with the same number of binary bits as the input. However, when using random() with calculated ranges, the output sometimes doesn't match the ...
0
votes
1
answer
62
views
Reading str from binary file given length in bytes
I have a binary file with the following structure:
• Byte 0: file version number (2)
• The remaining bytes represent records, which are composed of the following information:
– 2 bytes: lane ...
-6
votes
1
answer
190
views
Trying to make a simple binary counter
Trying to make a simple binary counter in C++:
#include <iostream>
#include <condition_variable>
#include <cstdlib>
using namespace std;
int c1 = 0;
int c2 = 0;
int c3 = 0;
int c4 = ...
1
vote
1
answer
99
views
python base64 string - how to decode first 8 bytes
I'm having some problems decoding what should be simple data.
I have a base64 string that represents a np.int64 followed by an array of np.float64. The size of the array is defined by the first np....
3
votes
1
answer
52
views
Python GEKKO - Non-zero Degrees of Freedom due to if2/if3
Currently I am building an economic model in Python GEKKO:
m = GEKKO()
m.time = np.arange(0, 200, 1)
#define the variables
consumption = m.Var()
tax = m.Var()
...
2
votes
1
answer
183
views
What is the fastest way to compute number of 1 bits in an array of bytes?
I might be silly to ask this, but I search around in google and did not got an definite answer(maybe I should be more careful).
Given a series of bytes, what is the fastest way to know the number of 1 ...
-12
votes
3
answers
313
views
Fastest way to find all permutations of 0, 1 of width n without itertools in pure Python?
What is an efficient way to get the same result as list(product((0, 1), repeat=n)) without using itertools and any imports?
For example, given n=3, the output be: [(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, ...
0
votes
2
answers
265
views
How to count the first N natural numbers in binary?
This may seem trivial but I haven't found a good solution to the problem. I have even found this: generate all n bit binary numbers in a fastest way possible. but I haven't found an exact duplicate.
...
0
votes
2
answers
157
views
2's complement operator on C
I'm reading The C Programming Language by K & R 2nd edition and got to the bitwise operators. Why, on C, the Complement (~) Operator applied to a N number, returns -(N + 1) ? When it normally just ...
-1
votes
1
answer
53
views
Is there a way to make Python interpret `~3` as an unsigned integer?
Is there a way to make Python interpret ~3 as an unsigned integer?
0
votes
1
answer
236
views
With objcopy, is there a reason to use -S with -O binary?
While researching embedded arm programming using gnu tools, I have found many examples, such as here or here, of build scripts where objcopy is invoked with -S -O binary, for example:
arm-none-eabi-...
0
votes
0
answers
63
views
Retrieving binary data with nanodbc from SQL Server fails
nanodbc::connection connection("Driver={SQL Server};...");
nanodbc::statement statement(connection);
nanodbc::prepare(statement,"select NULL, CAST(NULL AS VARBINARY(MAX))");
auto ...
1
vote
1
answer
200
views
How do I call a STOMP message with Postman using injection (Using Kotlin)?
I have the following...
@MessageMapping("/hello")
@SendTo("/topic/greetings")
@Throws(Exception::class)
fun greeting(message: TestMessage): Greeting {
However, when I run and send ...
1
vote
1
answer
158
views
Efficient seeded random shuffle for the bits in a 32-bit int?
Is there an algorithm that produces an efficient shuffle for a uint32 into a different uint32 that results in a 1:1 mapping when given a changeable random seed?
My initial direction on this is an ...
1
vote
1
answer
110
views
How to create a Sympy IndexedBase using a custom subclass of Symbol?
I want to create a 2-D matrix of binary variables x. For now I do it like this:
x = IndexedBase('x', shape=(imax,jmax), integer=True)
For a binary variable, the following identity holds: x_i**n == x_i ...
1
vote
0
answers
58
views
Bytes reversing and swaping in nodejs
Context
I have a file of binary logs and each log is 7 bytes.
The first 4 bytes is a timestamp (writeUInt32BE), the following 1 byte is an indicator (num 1 or 2 using writeUInt8) and the last 2 bytes ...
0
votes
1
answer
40
views
Resize image held in variable while preserving aspect ratio using PHP
There are tons of answers here in SO and elsewhere on the web about how to resize an image using PHP when the image is on disk. However, these do not work if the image is held in a variable. I believe ...
0
votes
0
answers
157
views
How does 7-Zip find .7z format archive at offset in a file?
I found that I can sandwich .7z archive files between other, binary data and 7za is still able to list and (presumably) extract files from this archive. I think this is useful eg to create a quintuple-...
0
votes
2
answers
96
views
What is the fastest way to serialize and deserialize a list of bools
orjson is already quite fast but I'm curious if there's an even faster way of getting from [1, 0, 0, 1] to 'intermediary_string' and back again, without storing any metadata separately (such as length)...
1
vote
2
answers
89
views
Convert float base 2 to base 10 to 100+ decimal places [closed]
I'm trying to find more decimal places to the 'Prime Constant'. The output maxes out at 51 decimal places after using getcontext().prec=100
from decimal import *
getcontext().prec = 100
base = 2
s = &...
1
vote
0
answers
473
views
Is it possible to obtain the aapt2 binary file built for the arm64 architecture?
I was trying various methods to use apktool on my Android-based server.
My Android server runs on an arm64 architecture, but when I extracted the aapt2 binary file required for APK building from ...
3
votes
1
answer
113
views
go install from private repository
I'm trying to install a Go binary via go install from my own private repository on github. I am able to get my repository to use the sdk, but not to install.
Here is my setup in ~/.gitconfig:
[url &...