473,378 Members | 1,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Binary Number Generation

34
Hello.

I want to be able to generate large binary numbers in C#, based on an integer, and later perform a bitwise operation on them - I'm talking being able to support numbers up to (and hopefully even beyond, just in case, 2^100)

The basis is that I have a database table with roughly 70 rows, each row has a unique identity value (1, 2, 3, 4, etc) and from that ID I want to generate a matching binary number, something like 2^(ID - 1). So, the binary ID for the row ID of 3 would be 4 = 2^(3-1). The binary ID for a row ID of 4 would be 8 = 2^(4-1). etc, etc. Any ideas on how to go about this? Or even what datatypes to use?

For those who care about the reasoning; I have a webpage in which users can view one, more or all of the values within this table and rather than pass 70+ IDs in the querystring I wanted to be able to pass in a binary number representing the selected rows; eg, Rows=9 would mean showing rows 1 and 4 (2^(1-1) = 1 + 2^(4-1) = 8) = 9.

Thanks
Jul 28 '09 #1
2 3265
GaryTexmo
1,501 Expert 1GB
I did a google search for large numbers in C# and found a few hits. It looks like you're pretty much going to have to make your own data type, which means if you want bit-wise operators on them, you'll have to implement them yourself.

http://www.codeproject.com/KB/cs/biginteger.aspx

Another approach you might consider is using several long ints.

For example... lets say you have an array of 10 unsigned integers, each one representing 32 rows in your database.

flags[0] = rows 0 to 31
flags[1] = rows 32 to 63
flags[2] = rows 64 to 95
...
flags[n] = rows (n * 32) to (n * 32 + 31)

You can't do a single bitwise operator on it, but you can parse through and figure out which rows are "set to return" fairly easily. It might save you some trouble in designing and implementing a big integer class.

Good luck!
Jul 28 '09 #2
Murdz
34
Yes I actually found that BigInteger datatype an hour or two after posting this and it does seem to solve the problem but thank you for your comment.
Jul 28 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Bern | last post by:
how to specifiy a binary number in c++? hex numbers are specified by 0x prefix
10
by: Ioannis Vranos | last post by:
I want to create some random numbers for encryption purposes, and i wonder if the following scheme makes it more hard to guess the underneath number generation pattern, than the plain use of...
4
by: Dimos | last post by:
Hello All, I need some help with random number generation. What I need exactly is: To create a few thousand numbers, decimal and integers, between 5 and 90, and then to export them as a...
3
by: Todd_Goselin | last post by:
Hello, I've got a problem that I can't fix by myself, I'm fairly new to programming in C and in Unix and so I'm having a tough time doing a simple task of converting a binary number to a string....
2
by: Hets | last post by:
Write a C program which can convert decimal number into binary number.
5
by: dmitrey | last post by:
hi all, could you inform how to print binary number? I.e. something like print '%b' % my_number it would be nice would it print exactly 8 binary digits (0-1, with possible start from 0) ...
0
by: castironpi | last post by:
On May 7, 3:31 pm, Mensanator <mensana...@aol.comwrote: ) for a in range( 10 ) ] ) 00000000 00000001 00000010 00000011 00000100 00000101 00000110
6
by: Fan924 | last post by:
How do I add random number generation to this background image slide show? Everything I try kills if. TIA _____________________________________ <html> <head> <meta http-equiv="Content-Type"...
2
by: star01daisy | last post by:
This is what the assignment says to do: Write a C++ program to do decimal-binary number conversions. The program gives the user a choice of conversion type (binary to decimal or decimal to binary)....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.