473,320 Members | 1,839 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,320 software developers and data experts.

BitWise split?

Hi,

Is there any easy way to split a bitwise value, for sample 127 to an array
into 1, 2, 4, 8, 16, 32, 64?

Regards
Fredrik Melin
Nov 21 '05 #1
6 1768
Nevermind, found it easy to do it in a FOR loop.

"Fredrik Melin" <me*@no-spam.dacsa-remove-this.net> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
Hi,

Is there any easy way to split a bitwise value, for sample 127 to an array
into 1, 2, 4, 8, 16, 32, 64?

Regards
Fredrik Melin

Nov 21 '05 #2
Frederik,

Better is in my opinion when you found it yourself to change the subject,
now it can look as an addition. However I am glad you sand this of course
and that you found your solution.

Cor

"Fredrik Melin" <me*@no-spam.dacsa-remove-this.net>
Nevermind, found it easy to do it in a FOR loop.

"Fredrik Melin" <me*@no-spam.dacsa-remove-this.net> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
Hi,

Is there any easy way to split a bitwise value, for sample 127 to an
array into 1, 2, 4, 8, 16, 32, 64?

Regards
Fredrik Melin


Nov 21 '05 #3
"Fredrik Melin" <me*@no-spam.dacsa-remove-this.net> schrieb:
Is there any easy way to split a bitwise value, for sample 127
to an array into 1, 2, 4, 8, 16, 32, 64?


Why would you "split" 127 to these numbers?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4
Herfried K. Wagner [MVP] wrote:
"Fredrik Melin" <me*@no-spam.dacsa-remove-this.net> schrieb:
Is there any easy way to split a bitwise value, for sample 127
to an array into 1, 2, 4, 8, 16, 32, 64?

Why would you "split" 127 to these numbers?

bitwise comparison. Alot of flags for API calls work that way.
That way you can pass alot of options with one integer (16 bit
integer=16 options).
--
Rinze van Huizen
C-Services Holland b.v.
Nov 21 '05 #5
"C-Services Holland b.v." <cs*@REMOVEcsh4u.nl> schrieb:
Is there any easy way to split a bitwise value, for sample 127
to an array into 1, 2, 4, 8, 16, 32, 64?

Why would you "split" 127 to these numbers?


bitwise comparison. Alot of flags for API calls work that way.
That way you can pass alot of options with one integer (16 bit integer=16
options).


Well, I know that, but I was slightly irritated by the "split" in the
subject.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
Hope this can help you but you need to shift with 128 and you never mention
what data type is your array so I use Integer for the example:

Dim arr(128) As Integer
Dim arr1(128 >> 1) As Integer
Dim arr2(128 >> 2) As Integer
Dim arr3(128 >> 3) As Integer
Dim arr4(128 >> 4) As Integer
Dim arr5(128 >> 5) As Integer
Dim arr6(128 >> 6) As Integer
Dim arr7(128 >> 7) As Integer

chanmm

"Fredrik Melin" <me*@no-spam.dacsa-remove-this.net> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
Hi,

Is there any easy way to split a bitwise value, for sample 127 to an array
into 1, 2, 4, 8, 16, 32, 64?

Regards
Fredrik Melin

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: jas_lx | last post by:
The basic understanding of what bitwise operators (& ^ | >> << ) comes fairly simple, as long as one has a fundamental understanding of bits, bytes and binary. Having done some Win32...
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
8
by: Paul E Collins | last post by:
Suppose I have a few Keys objects: Keys k1 = Keys.V; // V Keys k2 = Keys.Control | Keys.V; // Ctrl+V Keys k3 = Keys.Shift | Keys.J; // Shift+J I need to determine which of these include the...
9
by: Christopher Weaver | last post by:
I know that the bitwise AND of 8 and 4 will return 0 or false and the bitwise AND of 8 and 9 will return 1 or true but I don't know how to write the synax for it in C#. I have a value that ranges...
5
by: noridotjabi | last post by:
I'm learning to program in C and any tutorial or book that I read likes to briefly touch on birdies operators and then move on without giving any sort of example application of them. Call me what...
2
by: Mark Rae | last post by:
Hi, This isn't *specifically* an ASP.NET question, so I've also posted it in the ADO.NET group - however, it's not too far off-topic... Imagine a SQL Server 2005 database with a table with an...
3
by: Jay Ruyle | last post by:
I'm trying to figure out a way to list several items in a listbox and let the user select any number of items in the listbox. I have tried to code in the items as bitwise items but all it stores...
5
by: Gigs_ | last post by:
Can someone explain me bitwise expression? few examples for every expression will be nice x << y Left shift x >y Right shift x & y Bitwise AND x | y Bitwise OR x ^ y Bitwise XOR (exclusive...
10
by: Rob Wilkerson | last post by:
I'm attempting to do some work around existing code that uses bitwise operations to manage flags passed into a function and I'm quite frankly unequipped to do so. I've never done much with bitwise...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.