How to write code that converters a input file of binary numbers into octal. I had to write a code that converts it to decimal which I did, but now I'm supposed to write a code that converts it to octal by grouping the binary numbers in groups of 3 and then calling the binary to decimal function.
For example 10100 would be grouped 10 | 100. So I'd call binary to decimal on 10 and 100 and get 2 for 10 and 4 for 100, then place the numbers together to get 24, which is 10100 decimal in octal.
However, I cannot figure out how to group the numbers. (The number is type string by the way). Any tips would help thanks.
Simply add leading zeroes to your string if its length is not divisble by three then group them and convert to octal.
Related
I have a range of values and I want to count the decimal points of all values in the range and display the max count. the formula should exclude the zeroes at the end(not count ending zeroes in the decimal points).
for example, in the above sample, in the whole range the max of count of decimal places is 4 excluding the ending zeroes. so the answer is 4 to be displayed in cell D2
I tried doing regex, but do not know how do I do it for a whole range of values.
Please help!
try:
=INDEX(MAX(LEN(IFERROR(REGEXEXTRACT(TO_TEXT(A2:C4), "(\..+)")*1))-2))
Player0's solution is a good start, but uses TO_TEXT which seems to rely on the formatting of your cells.
If you want to safely compute the number of decimal places, use the TEXT function instead.
TEXT(number, format) requires a format whose max. number of decimal places has to be specified. There is no way around this, because formulas like =1/3 can have infinitely many decimal places.
Therefore, first decide on the max, precision for your use-case (here we use 8). Then use below function which works independently from your document's formatting and language:
=INDEX(MAX(
LEN(REGEXEXTRACT(
TEXT(ABS(A2:C4); "."&REPT("#";8));
"[,.].*$"
))-1
))
We subtract -1 since LEN(REGEXEXTRACT()) also counts the decimal separator (. for english, , for many others) .
Everything after the 8th decimal place is ignored. If all your numbers are something like 123.00000000987 the computed max. is 0. If you prefer it to be 8 instead, then add ROUNDUP( ; 8):
=INDEX(MAX(
LEN(REGEXEXTRACT(
TEXT(ROUNDUP(ABS(A2:C4);8); "."&REPT("#";8));
"[,.].*$"
))-1
))
I'm using odoo 8 and i imported an excel file which i introduced float values with 3 digits after the decimal point. After importing the data in odoo 8 as a tree view i noticed that odoo only displays 2 digits after the comma for these digits and it does the rounding however i want to keep the values as is in the excel file (without rounding and with 3 digits after the decimal point). Any idea for help please ?
You need to change the decimal precision using digits.
digits=(6, 2) specifies the precision of a float number: 6 is the total number of digits, while 2 is the number of digits after the comma. Note that it results in the number digits before the comma is a maximum 4
have declared a variable:
real*4 FACTOR
and then FACTOR=2.25
I want to output 2.25
Tried F3.2
Any help?
WRITE (lu09,9315)FACTOR
9315 FORMAT (F4.2)
The Fortran format F3.2 would output numbers up to .99, but anything larger won't fit. If you mean you want 3 digits before the decimal, change it to F6.2.
The first format number is the total field width, including the decimal and fractional digits.
For 2.25 to appear, the format width must be at least 4: F4.2
The f0.2 format gives the desired output, as demonstrated below. It writes the number with two digits after the decimal point and as many digits before the decimal point as needed.
program xwrite
implicit none
real*4 :: factor = 2.25
write (*,"(f0.2)") factor
end program xwrite
! output:
! 2.25
I want an input field with a decimal number upto 2 decimals after the point.
I am using
^\d+\.\d{0,2}$
which works just fine with any 2 decimal number after the point but it does not consider two zeros i.e. 2.00.
How can I include 2.11 and as well as 2.00?
Outside the binary 01010, octal 01122, decimal integer 1234 and hexadecimal 0xFF, does any one have any idea or trick how to build a new number format? For example, 0x11AEGH has it's range from 0 - 9 to A - H. I'm going to build password generator, so it would be very helpful if anyone can put something on it that might help.
Firstly, Is there any function which can do this? Basically I want to convert 0x11AEGH to binary, octal, integer and so on...
Formatting a number in an N-ary system requires two things: an alphabet, and an ability to obtain results of integer division + the remainder.
Consider formatting a number in a base-26 system using the Latin alphabet. Repeatedly obtain the remainder R of division by 26, pick letter number R, and add it to the front of the number that you are formatting. Integer-divide the number by 26, and use it in the next step of the algorithm. Stop when you reach zero.
For example, if you print 1234 in base-26, you can do it like this:
1234 % 26 is 12. Add M; 1234/26 is 47
47 % 26 is 21. Add V; 47 / 26 is 1
1 % 26 is 1. Add B. 1 / 26 is zero; stop.
So 1234 in base-26 is BVM.
To convert back, start from the front, and sequentially subtract the designated "zero" (A in case of the above example) from each digit, like this:
B-A is 1. Result is 1
V-A is 21. Result is 1*26+21, which is 47
M-A is 12. Result is 47*26+12, which is 1234.
You can probably use functions like Long.parseLong(String representation, int radix) and Long.toString(long value, int radix) as they are in Java. Other languages may also have the similar features.
This approach restricts the maximal possible radix (base) and you have no control over the characters representing different digits (alphanumeric chars are used). However it is a ready solution without any extra coding.