I have base-8 number 64276. How would I convert this number directly into base-32 without converting it into binary, decimal or any other base.
Edit: I am trying to solve the problem with pencil and paper
this sounds like a fun homework challenge, so here's a hint -- how could you convert a 5,000-digit base 64 number into base 32?
Related
I'm working with JSON, but I am somewhat new to it.
I'm trying to pad numbers to two characters because that makes the whole thing a lot easier and more uniform.
However, this makes numbers less than 10 throw the error "Expected comma".
Can someone please explain to me how to solve this/what the best workaround is?
Thanks!
From json.org:
A number is very much like a C or Java number, except that the octal
and hexadecimal formats are not used.
Numbers like: 01, 02, ... are not allowed.
How to convert this ,
I m not getting this?
I tried converting that into decimal 10*16^-1 and so on and got this (0.6708068848)10
Now it become really a complex task is there any short method to do so?
I think you're over-complicating it; I find it easiest to first convert it to binary (base-2) and then to octal (base-8).
Binary (bits partitioned into 3's because octal numbers have 3 bits):
0.101_010_111_011_101_000
Octal:
0.527350
Below is the converted values in different bases ie Hexadecimal, Decimal, Binary.
HexaDecimal - 33161fa59009c58000006198
Decimal - 15810481316372905437683540376
Binary - 1100110001011000011111101001011001000000001001110001011000000000000000000000000110000110011000
This one i have achieved correctly in Java. But for project i need to do this kind conversion in MySQL. I found out about Conv() http://dev.mysql.com/doc/refman/5.1/en/mathematical-functions.html#function_conv function which seems work for small no but not for big one sas given above.
Kindly help me if there is any work around for to get these desired results.
Regards,
Amit
I've written a simple text file compressor that uses Huffman coding. I encode the text and write the binary resulting from Huffman to a file. To decode, I read in the binary and step through the Huffman tree.
That part is straightforward. The problem arises with 0 and negative numbers. For practice/fun/learning, I decided to do my own binary conversion methods (from a Java byte to a string and vice-versa) and I decided to represent negative numbers by flipping the last bit to a 1.
E.g, -2 = 00000101;; 2 = 00000100 (the extra 0's for padding since even the unnecessary 0's are important in Huffman... it's irrelevant, though)
However, 0 = 00000000 = 00000001
This may not seem like a problem, but those two binary strings map to two different characters in the huffman tree.
Is there a better way handle negatives in binary that will get around this?
I'm not sure this will help you, but i will try:
First of all, there is different kind of binary, pure or the others. Binary pure DON'T allow negatives, it goes from 0.......
You can use magnitude and sign, another kind of binnary, it allows negative numbers, and the - or + sign is represented with the most important bit of the number, for example:
A number with 4 bits:
0100=2
1100=-2
(1 bit for the sign, the most important, the first left one, and the other 3 for the number)
You can use too the Two's complement, but it's harder and you need to get the number in binary and then translate it to the other type.
I hope i could help you, and sorry for the lot of mistakes in english!
I am working on a calculator that allows you to perform calculations past the decimal point in octal, hexadecimal, binary, and of course decimal. I am having trouble though finding a way to convert floating point decimal numbers to floating point hexadecimal, octal, binary and vice versa.
The plan is to do all the math in decimal and then convert the result into the appropriate number system. Any help, ideas or examples would be appreciated.
Thanks!
Hmm... this was a homework assignment in my university's CS "weed-out" course.
The operations for binary are described in Schaum's Outline Series: Essential Computer Mathematics by Seymour Lipschutz. For some reason it is still on my bookshelf 23 years later.
As a hint, convert octal and hex to binary, perform the operations, convert back to binary.
Or you can perform decimal operations and perform the conversions to octal/hex/binary afterward. The process is essentially the same for all positional number systems arithmetic.
What Programming Language are you using?
it is definatly a good idea to change everything into binary do the math on the binary then convert back. if you multiply a (unsigneD) binary number by 2, ti is the same as a Bit Shift Left ( << 1 in C), a division by 2 is the same as a Bit shit Right (>> in C).
addition and subtraction is the same as you would do in elementary school.
also, remember that if you cast a float as an int it will truncated it int(10.5) = 10;
I had this same problem a few days ago. I found http://www.binaryconvert.com, which allows you to convert between floating point decimal, binary, octal, and hexadecimal in any order you want.