1 in ASCII and 1 in Binary. Same thing? - binary

So, this question goes in the computer science world.
So, if we write number 1 in binary it will give us:
00000001
but we know that if 0 = 48, then 1 = 49 (in ASCII). So, if we represent 49:
00110001
are those two numbers the same?

Related

Convert a 16 Bit Binary Value to Octal

Hello I would like to know of a quick and easy way to perform a number conversion of this binary value:
1000100000001011
to octal.
In hex I can convert fairly quickly by hand to 0xAA0B. To come up with the decimal value of this binary takes a bit more work but eventually you can arrive at 32,768 + 2,048 + 11 = 34,827.
I know the octal pattern works like 8 = 10, 9 = 11 .... 16 = 20, 17 = 21 ... 24 = 30, etc. However I am having trouble converting to octal without a large amount of effort.
Could anybody clear this up for me and perhaps provide a short-hand method that can help convert binary to octal. Programming examples are nice but I'm really looking for an explanation. Thanks
The quickest method is to break the binary number into 3-bit chunks from the right end, pad with 0's from the left as needed, then convert each chunk to an octal digit.
For example,
1000100000001011 -> 001 000 100 000 001 011 [2 0's added to the left]
-> 1 0 4 0 1 3
-> 104013

How to convert Binary to Decimal and Octal?

I have a BINARY number which i want to convert it into the DECIMAL and OCTAL.
(0100 1111 1011 0010)2
I know how to convert it into the decimal. But the question making me confuse. Because middle of every 4 digits there is a space "0101 1111"
can u help me how to understand this question.
Thanks
First of all, make sure that number you are converting into Decimal and Octal is actually 'Binary' and not 'Binary Coded Decimal (BCD)'. Usually when the number is grouped into 4 binary digits, it represents a BCD instead of just binary.
So, once you make sure its actually binary and not BCD, the conversion to both decimal and octal are simple steps.
For binary to octal, you group the binary number into sets of 3 digits, starting form the Least Significant Bit(LSB or right-most) to the Most Significant Bit(MSB or left-most). Add leading zeros if a group of 3 digits can not be formed at the MSB.
Now convert each group of digits from binary to octal:
(000) -> 0
(001) -> 1
.
.
(111) -> 7
Finally put the numbers together, and there you have your binary converted to octal.
Eg:-
binary - 00101101
split into groups of 2: -> 000 101 101 -> 0 5 5 - > 55
Difference between'Binary Coded Decimal' and 'Binary':
For the decimal number 1248
the binary would simply be 10011100000
However, the BCD would be -> 0001 0010 0100 1000
The spaces are not part of the number, it's just to make it easier for humans to read. Conversion from binary to octal is simple. Group the binary digits into sets of 3 (from right to left, add extra 0s to the leftmost group, then convert each group individually. Your example:
0100 1111 1011 0010 -> 100 111 110 110 010 -> 47662
The space is just for readability. Especially nice if you try to convert this to hex, because 4 binary digits make up one hex-digit.
Firstly, those spaces are for human readability; just delete them. Secondly, If this is not for a computer program, simply open up the windows calculator, go to view, and select programmer. Then chose the bin radio button and type in your number. the qword radio button should be selected. If it's for a program, I will need to know what language to help you.
To convert octal to decimal very quickly there are two methods. You can actually do the actual calculation in bitshift. In programming, you should do bitshift.
Example octal number = 147
Method one: From left to right.
Step 1: First digit is one. Take that times 8 plus 4. Got 12.
Step 2: Take 12 times 8 + 7. Got 103, and 103 is the answer.
Ultimately you can use method one to convert any base into base 10.
Method one is reading from left to right of the string. Make a result holder for calculation. When you read the first leftmost digit, you add that to a result value. Each time you read a new digit, you take the result value and multiply that by the base of the number(for octal, that would be 8), then you add the value of the new digit to the result.
Method 2, bitshift:
Octal Number: 147.
Step 1: 1 = 1(bin) = Shift << 3 = 1000(result value)
Step 2: 4 = 100(bin) + 1000(result value) = 1100(result value)
Step 3: 1100(result value) Shift << 3 = 1100000
Step 4: 7 = 111(bin) + 1100000(result value) = 1100111
Step 5: 1100111 binary is 103 decimal.
In a programming loop, you can do something like the below, and it is lightning fast. The code is so simple that it can be converted into any programming language. Note that there isn't any error checking.
for ( int i = 0; i < length; i++ ){
c = (str.charAt(i) ^ 48);
if ( c > 7 ) return 0; // <- if char ^ 48 > 7 then that is not a valid octal number.
out = (out << 3) + c;
}

binary conversion using 3 figures system 0,1,2

Suppose system is evolved by extraterrestrial creatures having only 3 figures and they use the figures 0,1,2 with (2>1>0) ,How to represent the binary equivalent of 222 using this?
I calculated it to be 22020 but the book answers it 11010 .how this.Shouldn't i use the same method to binary conversion as from decimal to binary except using '3' here ???
I think you meant base 3 (not binary) equivalent of decimal 222
22020 in base 3 is 222 in decimal.
220202(your answer) in base 3 is 668 in decimal.
11010 (according to book) in base 3 is 111 in decimal.
222 in binary is 11011110
May be i will be able to tell where you went wrong if you tell the method you used to calculate base 3 equivalent of 222
Edit:
Sorry I could not understand the problem until you provide the link. It says what is binary equivalent of 222 (remember 222 is in base 3)
222 in base 3 = 26 in decimal (base 10)
26 in decimal = 11010 in binary
Mark it as accepted if it solved your problem.
Assuming the start is decimal 222.
Well, without knowing the system used in the book I would decompose it by hand in the following way:
3^4 = 81,
3^3 = 27,
3^2 = 9,
3^1 = 3,
So 81 fits twize into 222 , so the 4th "bit" has the value 2.
Remaining are 60. 27 fits twice into 60 so the next bit is 2 again.
Remaining are 6. 9 fits not into 6, so the next bit is 0.
Remaining are 6. 3 fits twice into 6, so the next bit is 2.
remaining are 0. so the last bit 0
This gives as result 22020.
One quick sanity check on how many "bits" are needed for representation of decimal 222 in a number system with 3 Numbers: 1+log(222)/log(3)=5,9 => nearly 6 "bits" are needed, which goes well with the result 22020.
First see how many figures you have, here we have 3 so
we have to convert 222 to binary when we have only 3 figures so
2×3^2+2×3^1+2×3^0 (if the number were being 121 then →
1×3^2+2×3^1+1×3^0)
which gives 26 then divide this with 2 until we don't get 1/2
when reminder is 1 then write 1 if 0 then 0 you will get
so we get 01011 just reverse it we have the answer
11010
enter image description here

What is wrong with my Ones Complement?

i want to do the following subtraction using ones complement
Octal(24)-Hex(4B) and give a binary answer
Octal(24) is 20 decimal
and Hex(4B) is 75 in decimal
20->10100
75->1001011
taking 1s complement of 75
0110100 and adding to 20
10100
+0110100
=1001000
adding the carry with the result
001000
+ 1
=001001 which is wrong
Where am i going wrong ?
I am new here, sorry if any mistakes in the way its typed.
You have a small few mistakes in your version. let me show you a correct solution and then show you your mistake(s)
We have the octal number 24 and the hex number 4B. both are fairly easy to translate to binary.
every octal digit represents 3 binary digits.
2 4
+++ +++
010 100
every hexadecimal digit represents 4 digits.
4 B
++++ ++++
0100 1011
now you build the complement:
~01001011
---------
10110100
the you need to add one. Otherwise you get 2 zeros. (+0 => 00000000, -0 => 11111111). this actually makes it a two's complement, but its needed unless you want weird results when crossing the 0-border
10110100
+00000001
---------
10110101
now your complement is done. Next step is to add both numbers
00010100 #The Octal 24
+10110101 #The complement
---------
11001001
The first digit is a 1 therefore its negative (as we'd expect since we did 20 - 75)
Therefore we need to reverse it.
First we subtract one: 11001000
Then we invert it again: 00110111
Which is decimal 55. Therefore 11001001 is decimal -55.
20 - 75 = -55
Voila, we are done :)
First tiny note: you made a small mistake when converting 0x4B (= Hex 4B) into binary format. one digit is wrong :)
Also, you forgot to add one. Then you did some weird stuff i don't get here:
adding the carry with the result 001000 + 1 =001001 which is wrong
Also, you didn't use fixed size numbers which made it impossible to you to find out if the result was negative. I sticked to 8 Bit here (except during octal -> binary conversion). (Keep in mind that with 8 bit your number range is from -127 to +128.) And in the end - as you couln't see its a negative number - you did not revert the process.
I hope this explanation helped you out :)

How exactly does binary code get converted into letters?

Out of curiosity, how exactly does binary code get converted into letters? I know there are sites that automatically convert binary to words for you but I wanna understand the specific, intermediary steps that binary code goes through before being converted into letters.
Here's a way to convert binary numbers to ASCII characters that is often simple enough to do in your head.
1 - Convert every 4 binary digits into one hex digit.
Here's a binary to hex conversion chart:
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = a (the hex number a, not the letter a)
1011 = b
1100 = c
1101 = d
1110 = e
1111 = f
(The hexadecimal numbers a through f are the decimal numbers 10 through 15. That's what hexadecimal, or "base 16" is - instead of each digit being capable of representing 10 different numbers [0 - 9], like decimal or "base 10" does, each digit is instead capable of representing 16 different numbers [0 - f].)
Once you know that chart, converting any string of binary digits into a string of hex digits is simple.
For example,
01000100 = 0100 0100 = 44 hex
1010001001110011 = 1010 0010 0111 0011 = a273 hex
Simple enough, right? It is a simple matter to convert a binary number of any length into its hexadecimal equivalent.
(This works because hexadecimal is base 16 and binary is base 2 and 16 is the 4th power of 2, so it takes 4 binary digits to make 1 hex digit. 10, on the other hand, is not a power of 2, so we can't convert binary to decimal nearly as easily.)
2 - Split the string of hex digits into pairs.
When converting a number into ASCII, every 2 hex digits is a character. So break the hex string into sets of 2 digits.
You would split a hex number like 7340298b392 this into 6 pairs, like this:
7340298b392 = 07 34 02 98 b3 92
(Notice I prepended a 0, since I had an odd number of hex digits.)
That's 6 pairs of hex digits, so its going to be 6 letters. (Except I know right away that 98, b3 and 92 aren't letters. I'll explain why in a minute.)
3 - Convert each pair of hex digits into a decimal number.
Do this by multiplying the (decimal equivalent of the) left digit by 16, and adding the 2nd.
For example, b3 hex = 11*16 + 3, which is 110 + 66 + 3, which is 179.
(b hex is 11 decimal.)
4 - Convert the decimal numbers into ASCII characters.
Now, to get the ASCII letters for the decimal numbers, simply keep in mind that in ASCII, 65 is an uppercase 'A', and 97 is a lowercase 'a'.
So what letter is 68?
68 is the 4th letter of the alphabet in uppercase, right?
65 = A, 66 = B, 67 = C, 68 = D.
So 68 is 'D'.
You take the decimal number, subtract 64 for uppercase letters if the number is less than 97, or 96 for lowercase letters if the number is 97 or larger, and that's the number of the letter of the alphabet associated with that set of 2 hex digits.
Alternatively, if you're not afraid of a little bit of easy hex arithmetic, you can skip step 3, and just go straight from hex to ASCII, by remembering, for example, that
hex 41 = 'A'
hex 61 = 'a'
So subtract 40 hex for uppercase letters or 60 hex for lowercase letters, and convert what's left to decimal to get the alphabet letter number.
For example
01101100 = 6c, 6c - 60 = c = 12 decimal = 'l'
01010010 = 52, 52 - 40 = 12 hex = 18 decimal = 'R'
(When doing this, it's helpful to remember that 'm' (or 'M') is the 13 letter of the alphabet. So you can count up or down from 13 to find a letter that's nearer to the middle than to either end.)
I saw this on a shirt once, and was able to read it in my head:
01000100
01000001
01000100
I did it like this:
01000100 = 0100 0100 = 44 hex, - 40 hex = ucase letter 4 = D
01000001 = 0100 0001 = 41 hex, - 40 hex = ucase letter 1 = A
01000100 = 0100 0100 = 44 hex, - 40 hex = ucase letter 4 = D
The shirt said "DAD", which I thought was kinda cool, since it was being purchased by a pregnant woman. Her husband must be a geek like me.
How did I know right away that 92, b3, and 98 were not letters?
Because the ASCII code for a lowercase 'z' is 96 + 26 = 122, which in hex is 7a. 7a is the largest hex number for a letter. Anything larger than 7a is not a letter.
So that's how you can do it as a human.
How do computer programs do it?
For each set of 8 binary digits, convert it to a number, and look it up in an ASCII table.
(That's one pretty obvious and straight forward way. A typical programmer could probably think of 10 or 15 other ways in the space of a few minutes. The details depend on the computer language environment.)
Assuming that by "binary code" you mean just plain old data (sequences of bits, or bytes), and that by "letters" you mean characters, the answer is in two steps. But first, some background.
A character is just a named symbol, like "LATIN CAPITAL LETTER A" or "GREEK SMALL LETTER PI" or "BLACK CHESS KNIGHT". Do not confuse a character (abstract symbol) with a glyph (a picture of a character).
A character set is a particular set of characters, each of which is associated with a special number, called its codepoint. To see the codepoint mappings in the Unicode character set, see http://www.unicode.org/Public/UNIDATA/UnicodeData.txt.
Okay now here are the two steps:
The data, if it is textual, must be accompanied somehow by a character encoding, something like UTF-8, Latin-1, US-ASCII, etc. Each character encoding scheme specifies in great detail how byte sequences are interpreted as codepoints (and conversely how codepoints are encoded as byte sequences).
Once the byte sequences are interpreted as codepoints, you have your characters, because each character has a specific codepoint.
A couple notes:
In some encodings, certain byte sequences correspond to no codepoints at all, so you can have character decoding errors.
In some character sets, there are codepoints that are unused, that is, they correspond to no character at all.
In other words, not every byte sequence means something as text.
Do you mean the conversion 011001100110111101101111 → foo, for example? You just take the binary stream, split it into separate bytes (01100110, 01101111, 01101111) and look up the ASCII character that corresponds to given number. For example, 01100110 is 102 in decimal and the ASCII character with code 102 is f:
$ perl -E 'say 0b01100110'
102
$ perl -E 'say chr(102)'
f
(See what the chr function does.) You can generalize this algorithm and have a different number of bits per character and different encodings, the point remains the same.
To read binary ASCII characters with great speed using only your head:
Letters start with leading bits 01. Bit 3 is on (1) for lower case, off (0) for capitals. Scan the following bits 4–8 for the first that is on, and select the starting letter from the same index in this string: “PHDBA” (think P.H.D., Bachelors in Arts). E.g. 1xxxx = P, 01xxx = H, etc. Then convert the remaining bits to an integer value (e.g. 010 = 2), and count that many letters up from your starting letter. E.g. 01001010 => H+2 = J.
http://www.roubaixinteractive.com/PlayGround/Binary_Conversion/The_Characters.asp it just looks here... (not HERE but it has a table).
There are 8 bits in a byte. One byte can be one symbol. One bit is either on or off.
Why not just do this take 010010001001001 split it into two bits 8 letter each (01001000, 01001001). Then issue the powers
01001000. 01001001.
The first 8 ignore the first three they determine if it's capital or not, the go right to left doing powers of 2 (2^1, 2^2 2^3 2^4 2^5). So then add all the ones up , there's only one, and it = 8, and te eight letter in the alphabet is h so our first bit is the letter h, try it on the other bit