How to maintain leading zeroes on binary conversions in Excel - excel

I want to convert a series of numbers < 1000 into binary to do some bitwise analysis in Excel
But the DEC2BIN function in Excel doesn't seem to allow me to specify leading zeroes for the smaller numbers. The BASE(x,2) functionn will handle the larger numvbers better than DEC2BIN, but still drops leading zeroes of the smaller numbers.
=BASE(999,2) returns 1111100111 but =BASE(511,2) returns 111111111
I would really like it to return 0111111111
Is it possible to do that in Excel?

You can just specify the minimum number of digits when using Base e.g.
=BASE(511,2,10)
Since your numbers are all less than 1000, 10 digits are sufficient.

Related

Function that returns number of significant figures after decimal point in specific formatting

Wondering if anyone knows a function that would return the number of significant figures after a decimal point? And even further how to put that number in a specific formatting?
For example if the number was 27.9834 it would return 0.0001. Or if it was 2.1 it would return 0.1.
You should be able to do this using a LEN and MATCH to get the number of decimal points, then its a simple "^" function to get the decimal place.
Assuming your number is in Cell A1:
=10^-(LEN(A1) - FIND(".",A1))
Just make sure you are showing the right number of significant digits in the result cell or it will just look like zero.
The LEN() counts the number of characters and then you subtract the number of characters from the left to where the decimal is. I think there is an upper limit on the number of decimals that excel can handle, but i don't recall what it is.
Another method might be,
=AGGREGATE(14, 6, POWER(10, -(ROW($1:$16)-1))/(TRUNC(A2, ROW($1:$16)-1)=A2), 1)

Numbers stored as text - when converted to numbers, digits disappear

I have a column of data with numbers stored in text.
The numbers look like this: 735999114002665788
If I select any cell in this column and refer to it with the function =value(), the number shows up as 735999114002665000.
As you can see the last three digits are 0. This happens all the time with numbers this long - but NOT with numbers containing less digits.
Am I trying to convert a number that's too large or what's up? Please help! I've tried every form of text-to-number method with identical results :(
Excel's number precision is 15 digits, which is why you're losing the last three digits when converting your 18 character string
https://support.office.com/en-us/article/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3#ID0EBABAAA=Excel_2016-2013
Excel only allows a maximum of 15 digits of precision for each number in a cell. The reason why this number:
735999114002665788
becomes this:
735999114002665000
is because Excel is choosing to retain the 15 most significant digits in the number. This means that the ones, tens, and thousands digits are being tossed out.
By the way, this question has been asked before on SuperUser, and you can read about it here:
https://superuser.com/questions/437764/why-is-excel-truncating-my-16-digit-numbers

Convert decimal to whole number - but ignoring value

I know how to isolate the decimal using the TRUNC() function, as well as taking the original value and subtracting this truncated part.
And I can then multiply to get whole number.
But that only works if all my decimals are the same place. I want something that will get me the amount after the decimal point as a whole number, regardless of how many places.
eg: 12.2 would return 2
12.21 would return 21
With data in A1, consider:
=IF(ISERROR(FIND(".",A1)),A1,--MID(A1,(FIND(".",A1)+1),9999))
Naturally leading zeros in the output are dropped:

bin2dec for numbers longer than 10 bits in excel

I have an excel with 28 position binary numbers. I need to convert them to decimal numbers, but function bin2dec don't work with numbers longer than 10 bits. Can anyone help me with this?
Use the following formula to mimic a BIN2DEC function that coverts larger than 10 bits.
=SUMPRODUCT(--MID(A2,LEN(A2)+1-ROW(INDIRECT("1:"&LEN(A2))),1),(2^(ROW(INDIRECT("1:"&LEN(A2)))-1)))
Remember that Excel has a numerical precision of 15 digits. If you want 28 digits, format the cell as Text or preface the string of digits with a single tick (e.g. ') as a PrefixCharacter property.
   
I brute forced it with the math, may be inelegant, but for a 16 bit number where leading 0's will be displayed this works and can easily be adapted to longer strings
This works well if you are working with fixed length words, like verifying values in memory, BIT registers, etc.
16 bit
=BIN2DEC(LEFT(R5,8))*2^8+BIN2DEC(RIGHT(R5,8))
32 bit could be
=BIN2DEC(MID(R10,1,8))*2^24+BIN2DEC(MID(R10,9,8))*2^16+BIN2DEC(MID(R10,17,8))*2^8+BIN2DEC(MID(R10,25,8))
Again, this works if you have a fixed length input, leading zeros are displayed.

Stata: Variable type (8-digit numbers)

input a
88888888
99999999
end
export excel a.xlsx, replace
Then, if I open the excel file, the numbers are shown as 8.89e+07 and 1.00e+08. How can I restore these to the original numbers. Do I have to do this in Excel? Is there any way to prevent Stata from converting those numbers to the "scientific" format?
The effect of your input command is to read those numbers into variables of float type. But there aren't enough bits in a float to hold 99999999 exactly. This is well documented.
See e.g. the help for data types:
"floats have about 7 digits of accuracy; the magnitude of the number does not matter. Thus, 1234567 can be stored perfectly as a float, as can 1234567e+20. The number 123456789, however, would be rounded to 123456792. In general, this rounding does not matter.
If you are storing identification numbers, the rounding could matter. If the
identification numbers are integers and take 9 digits or less, store them as longs;
otherwise, store them as doubles. doubles have 16 digits of accuracy."
So you degraded your data by using an inappropriate data type. That is the issue, not export excel.

Resources