| |

VerySource

 Forgot password?
 Register
Search
View: 683|Reply: 6

The problem of data generation! !! !! !! !!

[Copy link]

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-10 03:00:02
| Show all posts |Read mode
For example, a random number is generated between 0 ~ 15.
1. How to convert it to binary.
2. For example, if it is 14, it should be 1110. If it is 8, then it is 111. How to change it to 0111?

Thank you!
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-6-3 00:30:01
| Show all posts
int temp = 8;
Convert.ToString(temp,2);
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-6-3 09:45:01
| Show all posts
In addition, the binary of 8 is not 0111 but 1000
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-6-3 17:30:01
| Show all posts
The easiest way is to calculate the string converted from 0-15 to binary in advance, and then store it in a string array, and then obtain the corresponding string according to the value.
Reply

Use magic Report

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-6-4 21:30:01
| Show all posts
Thank youpsycholmu
But how can it be fixed at the time of output?

For example, 15 is 1111
7 is 111 (Khan!) How do you make them all four? 7 for 0111
Or 1 is 0001
Thank you! Waiting online~~
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-6-7 08:45:01
| Show all posts
The company is busy, sorry
E.g
string s = Convert.ToString(7,2);
s = s.PadLeft(4,'0');
Reply

Use magic Report

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-6-9 18:45:01
| Show all posts
Good pull, haha, thank you! ! !
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list