binary representation in Python and keeping leading zeros
I wanted to use the base64 Python library to encode a sequence of binary digits into base 64. Would it be possible to do it without converting to a string? If not, what is the best way to do it, assuming that my string of 1/0 digits may not be an integer multiple of 8, it may even be an odd number.
Understanding binary numbers in terms of real world objects [closed]
Closed 9 years ago.
Has Little Endian won?
When teaching recently about the Big vs. Little Endian battle, a student asked whether it had been settled, and I realized I didn’t know. Looking at the Wikipedia article, it seems that the most popular current OS/architecture pairs use Little Endian but that Internet Protocol specifies Big Endian for transferring numeric values in packet headers. Would that be a good summary of the current status? Do current network cards or CPUs provide hardware support for switching byte order?
Why don’t computers store decimal numbers as a second whole number?
Computers have trouble storing fractional numbers where the denominator is something other than a solution to 2^x. This is because the first digit after the decimal is worth 1/2, the second 1/4 (or 1/(2^1) and 1/(2^2)) etc.
Which numeral systems are useful in computer science?
I am wondering which numeral system different programmers are using, or would use if their language has support for them. As an example, in C++ we can use:
Filling array with numbers from given range so that sum of adjacent numbers is square number
Problem: Fill all the cells using distinct numbers from <1,25> set, so that sum of two adjacent cells is a square number.
Is there something special about the number 65535?
2¹⁶-1 & 2⁵ = 2⁵ (or? obviously ?)
Why is the minimum value of ints, doubles, etc 1 farther from zero than the positive value?
I know it has something to do with 2’s complement and adding 1, but I don’t really get how you can encode one more number with the same amount of bits when it comes to negative numbers.
Algorithm for picking reasonable min/max vals given a single value
I am making a simplistic in-browser IDE for some very domain-specific coding. Because I like Bret Victor’s thoughts on Learnable Programming so much I thought I’d throw in some draggable numbers ala Tangle.js (click here to see what I’m talking about).
What is the time complexity of the algorithm to check if a number is prime?
What is the time complexity of the algorithm to check if a number is prime?