answersLogoWhite

0

What is binary in R programming?

Updated: 10/24/2022
User Avatar

Ahamsharma

Lvl 1
7y ago

Best Answer

Binary in R is the same as binary in any other programming language. The language doesn't actually change the meaning of binary any more than it can change the meaning of decimal, octal or hexadecimal. These are all symbolic representations (notations) for digital information. When we see the symbol 42 we instantly recognise it as the value forty-two because we automatically assume numeric symbols are always written in decimal notation. However, the computer represents the value forty-two as 00101010, which is the binary equivalent.

In order to present the decimal value to the user, the computer must convert the value 00101010 to the string "42". This is achieved through binary division by ten (00001010 in binary) and taking the remainder:

00101010 / 00001010 = 00000100 r 00000010

00000100 / 00001010 = 00000000 r 00000100

The remainders are decimal 2 and 4 respectively. Now we convert each of these digits to their equivalent ASCII character code by adding 48 (binary 110000), which is the ASCII code for character '0':

00000010 + 00110000 = 00110010

00000100 + 00110000 = 00110100

We output these two ASCII character codes in reverse order, so we now have {00110100, 00110010} which is {52, 50} in decimal. ASCII character code 52 yields '4' while ASCII character code 50 yields '2', which gives us the complete string, "42", which can now be presented to the user.

Converting the other way takes the user-input string "42" and stores the value 00101010:

First, subtract character code '0' (48 decimal) from each character:

00110010 - 00110000 = 00000010 (50 - 48 = 2)

00110100 - 00110000 = 00000100 (52 - 48 = 4)

Multiply each digit by increasing powers of 10:

00000010 * 00000001 = 00000010 (2 * 10^0 = 2) 00000100 * 00001010 = 00101000 (4 * 10^1 = 40)

Finally, sum the products:

00000010 + 00101000 = 00101010 (2 + 40 = 42)

If we wish to see the binary representation of an integer, R provides the Int2Bin function:

>intToBin(42, 8)

[1] "00101010"

Here we've requested the binary equivalent of the decimal value 42 in 8-bit binary which, as we've already established, outputs the binary value 00101010.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is binary in R programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What does bianry code and programming have in common?

Computers read binary code. Binary code is made up of 1's and 0's. Programming sometimes uses Binary Code, sometimes not. That's what they have in common.


What is The lowest programming language that humans use?

binary


What is R programming?

R programming simply means developing and writing programs using the R programming language. R is primarily used by statisticians and data miners.


What is the difference between unary and binary?

In programming a unary and binary operator defines how many components make up an expression.


What is a binary programming language that the computer can run directly?

Machine language.


Which programming language consists entirely of 0s and 1's?

Binary


What is a binary code?

Binary code is a language used in computer programming and is made up entirely of ones (1) and zeroes (0).


What are the examples of middle level programming language?

binary language


What does binary code mean?

170/2 = 85 R 0. Therefore binary number so far is 0.85/2 = 42 R 1. Therefore binary number so far is 10.42/2 = 21 R 0. Therefore binary number so far is 010.21/2 = 10 R 1. Therefore binary number so far is 1010.10/2 = 5 R 0. Therefore binary number so far is 01010.5/2 = 2 R 1. Therefore binary number so far is 101010.2/2 = 1 R 0. Therefore binary number so far is 0101010.1/2 = 0 R 1. Therefore binary number so far is 10101010.The integer portion of last division was 0 so for the decimal number 170, the binary equivalent is 10101010.


What has the author R Schneyer written?

R. Schneyer has written: 'Modern structured programming' -- subject(s): Structured programming


What is binary translation process in computer networking?

The binary translation process is the complex procedure in which a computer converts binary into commands to run the computer. Learning how to use this function is one the most difficult parts of programming.


What has the author Shannon R Fischer written?

Shannon R. Fischer has written: 'How computer programming works' -- subject(s): Computer programming