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

vec - a misunderstanding

I am trying to understand how the vec function is used.

I have produced the following code, but the behaviour is not as expected.

$binstring = '@' ; # 01000000 binary ascii code
print vec($binstring,0,1); # returns 0, the binary value of bits 0 and 1
vec($binstring,0,1) = 3; # bits 0 and 1
print $binstring; # returns A, I am expecting C (binary ascii code 01000011)
vec($binstring,2,1) = 3; # bits 2 and 3
print $binstring; # returns E, I am expecting O (binary ascii code 01001111)

Documentation tells me that vec has the syntax:

vec EXPR, OFFSET, BITS

where BITS is a power of 2 from 1 to 32.

I presumed offset of zero would give me the leftmost (most significant) bit.
It actually gives me the rightmost bit.

Is this expected behaviour?

The number of bits is a power of two ranging from 1 to 32. Presumably this
means that minimum element size (BITS = 1) is 2^1 = 2 bits, and therefore I
cannot use single bit elements.

Is it correct that if BITS = 1, my elements should be 2 bits wide?

I presumed that the offset was in number of elements, so an offset of 1, would
point to bits two and three. It actually appears to point to bit 1, which is
part of the first element.

Presumably then, offset is in number of bits, not number of elements. Is this
correct?

When I set the value of my element to three, indicating both bits set to 1, I
only appear to be getting a single bit set.

What is going on here?

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Telephone: (0121) 247 1596
International: 0044 121 247 1596

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/

Mar 18 '06 #1
1 2700
ma********@hotpop.deletethisbit.com (Mark Hobley) wrote:

The number of bits is a power of two ranging from 1 to 32. Presumably
this means that minimum element size (BITS = 1) is 2^1 = 2 bits, and
therefore I cannot use single bit elements.
Yes you can, but you can't use 3 or 5, the *number* has to be a power of
two, so 2^0, 2^1, 2^2, 2^3, 2^4.
Is it correct that if BITS = 1, my elements should be 2 bits wide?


No, it's 1, but you can't use 3 bits wide, since 3 is not a power of 2 (if
I read the documentation correctly).
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
Mar 18 '06 #2

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

Similar topics

14
by: Alexander May | last post by:
When I define a function in the body of a loop, why doesn't the function "close" on the loop vairable? See example below. Thanks, Alex C:\Documents and Settings\Alexander May>python Python...
15
by: Bill Mill | last post by:
Hello all, I have a misunderstanding about dynamic class methods. I don't expect this behavior: In : class test: ...: def __init__(self, method): ...: self.method = method ...:...
2
by: bardos | last post by:
Hello, I'm relatively new to C++ so I hope you can help clear up a problem. You may well be able to do so before checking the example, so don't be put off by the long post :) The problem regards...
4
by: Tim Haughton | last post by:
I think I might be misunderstanding just what the LoadXml method is doing. I have 2 seemingly identical XmlDocuments, an XPath query succeeds on one of them, and fails on the other. Can anyone tell...
3
by: Philip Tripp | last post by:
I've read numerous sources stating that view state can be disabled per control, and per page, but can't seem to keep web form controls from remembering their state on a postback. I'm using VS.Net...
12
by: Dennis | last post by:
I get the following results: Cint(&HC5798A2F) returns -981890513 as it should and Clng("&HFFFFFFFFC5798A2F") returns -981890513 as it should. However when using a string ...
6
by: Shawn Wildermuth | last post by:
I have a web project whose web.config has a ConnectionString setup. I have a second assembly with my Typed DataSets. The designer has created an App.config file with a connection string in it for...
7
by: Nathan Truhan | last post by:
All, I think I may have uncovered a bug in the IsNumeric function, or at least a misunderstanding on functionality. I am writing a Schedule Of Classes Application for our campus and have a...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.