hex array to array of 16 bit numbers?

Hello everyone,

I would really appreciate some of your expertise or even just
pointers.  How do I convert this hex array variable "buffer" to array
of 16 bit numbers?

>>> 
>>> from ctypes import *
>>> buffer = c_buffer(8)
>>> status = ni.DAQ_Op (deviceNumber, chan, gain, buffer, count,
sampleRate)
>>> print "repr(buffer.raw) =", repr(buffer.raw)

repr(buffer.raw)= '\xcd\x00\xce\x00\xce\x00\xce\x00'
>>> 

Any ideas would be greatly appreciated!

Todd
0
piir (66)
12/25/2003 10:06:02 AM
comp.lang.python 74775 articles. 15 followers. Post Follow

4 Replies
154 Views

Similar Articles

[PageSpeed] 57
[posted and mailed]

piir@earthlink.net (Todd Gardner) wrote in
news:9b849915.0312250206.61d89841@posting.google.com: 

> Hello everyone,
> 
> I would really appreciate some of your expertise or even just
> pointers.  How do I convert this hex array variable "buffer" to array
> of 16 bit numbers?
> 
>>>> 
>>>> from ctypes import *
>>>> buffer = c_buffer(8)
>>>> status = ni.DAQ_Op (deviceNumber, chan, gain, buffer, count,
> sampleRate)
>>>> print "repr(buffer.raw) =", repr(buffer.raw)
> 
> repr(buffer.raw)= '\xcd\x00\xce\x00\xce\x00\xce\x00'
>>>> 
> 
> Any ideas would be greatly appreciated!
> 
> Todd

First I think your missing the fact that the 'hex' values you're seing is 
simply an encoding of the byte value at that byte-index in the buffer, ie. 
your buffer starts with bytes containing the following values:

  [205] [0] [206] ...

besides that, you're looking for the struct module :-)

-- bjorn
0
12/25/2003 11:02:19 AM
That's all I needed to make it work.

Thank you for pointing me to the correct module.

Todd
0
piir (66)
12/26/2003 7:31:57 PM
Todd Gardner <piir@earthlink.net> wrote:
> Hello everyone,
>
> I would really appreciate some of your expertise or even just
> pointers.  How do I convert this hex array variable "buffer" to array
> of 16 bit numbers?
>
>>>> 
>>>> from ctypes import *
>>>> buffer = c_buffer(8)
>>>> status = ni.DAQ_Op (deviceNumber, chan, gain, buffer, count,
> sampleRate)
>>>> print "repr(buffer.raw) =", repr(buffer.raw)
>
> repr(buffer.raw)= '\xcd\x00\xce\x00\xce\x00\xce\x00'
>>>> 
>
> Any ideas would be greatly appreciated!

I think the struct.unpack() method is what you're looking for here:

    http://www.python.org/doc/current/lib/module-struct.html

If you've got four 16-bit numbers, then:

    import struct
    status_tuple = struct.unpack('4h', buffer.raw)

should give you what you want. Read the documentation for the meaning of
the various format characters.

-- 
Robin Munn
rmunn@pobox.com
0
rmunn1 (50)
12/26/2003 8:21:04 PM
Todd Gardner wrote in message
<9b849915.0312261131.1344f5d4@posting.google.com>...
>That's all I needed to make it work.
>
>Thank you for pointing me to the correct module.
>
>Todd

Just as a heads up, your code uses the name "buffer", which clobbers the
builtin function "buffer." (Which, honestly, I've never seen used, but
still....)

0
12/27/2003 12:03:58 AM
Reply:
Similar Artilces:

postgreSQL array datatype and DBI
PostgreSQL has an Array type (other DBs probably do too but I only know postgres). How do I bind a variable to a column of type Array using DBI? Is it possible? Binding a ruby array to it does not work. TIA Michael ...

Hex String to Number to Array... I think...
Hello to the group, &nbsp; Here's my dillemma... I'm interested in a specific output from my device. The expected output is 256&nbsp;values, as a row of 512 byte (Hex). To simplify communication, I used the LabVIEW Serial VI and added a terminal at the "Read String". This outputs a string (when displayed as "Hex Display") like 0200 0200 ... ...&nbsp;0200 0100. I wired that output into the "String" input of a Hexidecimal String to Number conversion. Then, I am using a&nbsp;Build Array, wired into the single element. Finally,&nbsp;the app...

How do I use use multiple arrays with one function?
Hi all. I have a problem I have not been able to find a reference about. I am using VB6 and am only a hobbyist programmer. I have 7 arrays of type MyData. Type MyData has 23 elements. Which array that is operated on depends on 1 of 7 options Currently if I want to write to an array I have to do this: if opt1 then array1(x).data1= 36 array1(x).data2= 23 .. array1(x).data23= 69 else if opt2 then array2(x).data1 = 43 array2(x).data2 =77 .. array2(x).data23 =44 else if opt3 then array3(x).data1 = 78 array3(x).data2 = 63 .. array3(x).da...

The most efficient way to innitialize an array with an innitialization list
Hi! int [] arr = {21, 22, 23}; int [] arr = new int [] {21, 22, 23}; The second form will create an array with 3 elements then it will copy the values of the innitialization list (21, 22, 23). The first form just declares a reference to the array {21, 22, 23} - no suplimentary memory is allocated and no copy operation takes place, so the first form should be preffered. Is this true ? ... or the compiler makes some optimizations, practically rendering the 2 forms equivalent ? I doubt that it will, since the new operator guarantees that new memory will be allocated. Regards, Razvan &...

Re: Can you do array processing and a proc nlp from within proc #6
I thought you wanted to run PROC NLP. What is the array for? On Jan 8, 2008 3:31 PM, Randall Powers <powers_r@bls.gov> wrote: > Ok, that gives me a data set with 10 rows and 3 columns. > > Perhaps a dumb question, but how do I now get this dataset into a two > dimemsional 10x3 array? > > Thanks again! > > > On Tue, 8 Jan 2008 14:10:17 -0600, data _null_, <datanull@GMAIL.COM> wrote: > > >Try the FROM clause > > > >create out.testset2 from x; > >append from x; > > > > > > > >On Jan 8, 2008 1:26 PM, Randal...

JSON array problem
Hi, I have the following problem: when I try to access to the array in Big object I have 'Big is not defined' but when I try to access to the function in Low object I have no error!!!! WHY?? Big = { One: [1, 2, 4], Two: [1, Big.One, 5] }; alert(Big.Tow) // error Low = { One: function() { }, Two: function() { Low.One(); } }; Low.Two(); // no error Thank On 2008-10-24 11:42, xdevel1999 wrote: > Hi, I have the following problem: > when I try to access to the arr...

Pass By Ref for String Array issue with VBscript
Hello, I am trying to call an ActiveX Dll from VBscript in ASP (it works fine when I calll the DLL from a VB6 exe). The Pass By Reference call takes a String array and a Long as arguments. In the DLL I have changed these to Variant so that ASP will understand them, like so: Public Sub EnumerateAllSections(ByRef sSections As Variant, ByRef iCount As Variant) In the ASP code I have declared the variables with just the DIM keyword, as shown below: Dim sSections Dim iSectionCount And I call the Sub in ASP as shown here: With m_cIni .Path = "F:\from vinny\DOCOweb\set...

Finding array patterns and outputting values
p = 5 9 7 4 2 1 3 6 8 q = 5 9 7 4 2 1 3 6 8 D(p,q) ans = 1 1 0 0 0 0 0 0 0 (5) 1 1 1 0 0 0 0 0 0 (9) 0 1 1 1 1 1 0 0 0 (7) 0 1 1 1 1 1 0 0 0 (4) 0 1 1 1 1 1 0 0 0 (2) 0 0 1 1 1 1 0 0 0 (1) 0 0 0 0 0 0 1 0 0 (3) 0 0 0 0 0 0 0 1 0 (6) 0 0 0 0 0 0 0 0 1 (8) I have an array like the one above and I need the line numbers of the block of 1's, eg: elements [7 4 2 1]. How do I find these elements and save them to a new array? Thanks! Can you be specific about what pattern you're trying to find. You say the result for your example is [7 4 2 1] but I can't ...

Text objects and unicode hex strings
Hi, I'm having a problem that I don't understand. The PDF specs state that wherever a string is needed I can use the alternative hex encoded form like: <34353637> Tj instead of (4567) Tj This works. However, I can't get the Unicode version work. The specs state that you need to prefix a unicode string with a byte order marker (U+FEFF) so this should work: <FEFF0034003500360037> Tj but it does not. It works for things like bookmarks and document properties but not for text objects. It must be something simple I'm doing wrong, any comment high...

array handling
Hi all, I am a newbie in IDL. Although I cannot handle the following problem, I am sure for the 'Masters' this is peanuts. The problem: I wish to filter an array of redundant data in one line. This is a part of the line to be filtered: -Inf -NaN -Inf 0.542373 2.39394 2.28125 0.000000 0.000000 0.000000 3.21053 1.21839 0.000000 -NaN 0.967213 2.03448 0.724138 0.000000 0.000000 0.000000 -NaN With WHERE I can get rid of the zeros, but I dont know how to exclude the '-NaN' and '-Inf'. A...

Array of hashes issue
Hi, I'm new to ruby and am trying to do a project so I can learn ruby and build a tool I need for my job. I want to creat an array of hashes and then get the information out. This is what I have right now: this is in my getIssuesInFileter class: @issues = @jira.getIssuesFromFilter(@key) @output = Array.new(@issues.length, Hash.new) @issues.each { |fl| @output << {:id => fl.id, :assignee => fl.assignee, :description => fl.description, :status => fl.status, :type => fl.type, :updated => fl.updated} } return @output This is ...

Unpacking a cell array into multiple variables
Hi! I have an MxN cell array, C, I'd like to unpack--using assignment syntax and without explicit looping--into N variables, i.e., I'd like to do something like: [v1, v2, ..., vN] = C; so that v1, v2, ..., vN consist of the columns of C (I don't care if the vi are column or row vectors). This works fine if M = 1, of course, but I can't figure out how to make it work for M > 1. Is it possible and if so, how? Thanks! DG "David " <dgol461@ecy.wa.gov> wrote in message <i8ia12$6c$1@fred.mathworks.com>... > Hi! I have an MxN cell array, C...

WEP passphrase to hex string conversion
Hi All, Recently I was given an ASCII passphrase for a WLAN router, but found that the WLAN card's config utility did not have the required conversion feature. Fortunately I found several online web sites that do the conversion for you (accessed using a conveniently un-encrypted WLAN router) so I could get connected... I have now added a WEP passphrase to hex string converter to the MD5.f file at http://www.inventio.co.uk/md5.f . ( And yes, I know that I shouldn't be using WEP - its a very old router and doesn't support WPA ;) Best Regards, Howerd ...

How to convert an hex string to a Hex number
Hi, I'd like to use a var to hold a Hex number. But in this code: var a = "ffff00" a is a string. var a=ffff00 will not work either. How can I put a Hex number ffff00 into a var? Thanks Chris yma@kicon.com (chirs) writes: > I'd like to use a var to hold a Hex number. But in this code: > > var a = "ffff00" > > a is a string. var a=ffff00 will not work either. How can I put a > Hex number ffff00 into a var? var a = 0xffff00; In Javascript, and most other languages with a C like syntax, hexadecimal numbers are written with a prefix &quo...

comp.cad.autocad AutoLISP FAQ (part 1/2)
Posted-By: auto-faq 3.2.1.5 Archive-name: CAD/autolisp-faq/part1 URL: http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html Version: 2.28 Last-modified: 2002-06-25 Posted-By: Reini Urban <rurban@x-ray.at> Posting-Frequency: monthly Copyright: see Appendix [A] Welcome to the comp.cad.autocad AutoLISP FAQ by Reini Urban <rurban@x-ray.at> Autolisp is a scripting language for AutoCAD, a well known CAD package. This AutoLISP FAQ is posted to comp.cad.autocad, alt.cad.autocad and the *.answers groups monthly. Some AutoCAD FAQ's are at http://ww...

Is there a way to autoincrement a field with mixture of alpahbetic characters and numbers?
I have a feeling I'll be forced to use a script and a trigger for this type of field format but I'm wondering if any of your wizards could point at a simple way I could do something like this: For example, if I want to be able to keep track of new orders following this incrementing convention: ORD100000001 ORD100000002 ORD100000003 .... etc ... Does MSSQL2000 have features that I can simply set for this kind of field or will I be resorting to writing up a SQL script and a trigger? Jared Evans (jnevans@gmail.com) writes: > I have a feeling I'll be forced to use a script and ...

what is incorrect about my usage of array with port entity?
library ieee; library work; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity delay_line_interleaved is generic( numtaps : integer := 18; wordlength_in : integer := 14; coefflen : integer := 20 ); port( -- INPUT PORTS -- clkin : in std_logic; rst : in std_logic; ena : in std_logic; in_pddc : in std_logic_vector(wordlength_in-1 downto 0); --enough bits here and other places to handle number of adds? -- OUTPUT PORTS -- dv_out : out std_logic; x_delay_line : out array (0 to coefflen-1) of std_logic_vector(wordlength_in-1 do...

differences between hashes and arrays ?
Hi folks I am not an expert in perl but correct me if I am wrong - is it true you can use a hash and work with it just as you would an array - what are the differences between them (besides in an array you can have a multidimensional array) ? why arent folks using hashes instead of arrays since (I believe) they are faster to access and take up the same or less memory than arrays.. Thanks, Jack Thus spoke Jack (on 2006-09-22 16:55): > is it true you can use a hash and work with it just as you would an > array - what are the differences between them (besides in an array you > can...

[array values] -- could someone TIP this, please? :-)
A co-worker and I were lamenting today, yet again, that we wished that there was a [array values] subcommand analogus to [array names] which simply returned the values in an array. Obviously, it's simple to do with a small proc: proc arrayValues {&array} { upvar ${&array} array foreach {name value} [array get array] { lappend list $value } return $list } However, it'd be nice if this were built-into [array]. Donal, could you please TIP this -- thanks! -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Ne...

Arrays and SQL
Hi, No, this is not the same as a previous posting !! (Well, kind of...) I am planning an application whereby an array of a user data type (containing group and location details - both strings) needs to be stored in a single array with a maximum of 20 entries. This array is supposed to lie in a 'control' table in the database which is to hold site-specific information. Is there an easy way of putting the whole array into a single entry in the table or do I have to split it down and have, say, Entry1 to Entry20. I am using VB6 and know that the split function is available...

FA Bits #5
Hi I've just put some stuff up on eBay; see the link below. One item I'm at a loss to remember. I think it's a video digitiser podule, but any more information gratefully received. It's got CVBS and S-video ports, and is labelled as "techno (eye)", where the (eye) is a symbol rather than words. In addition, I have a few A7000+ machines. These haven't been tested or cleaned yet, but have all got hard drive and CDROM. Having had enquiries from the States about A3000s, I think these might be better for export. Stripping out the drives takes the weight below a kilo,...

Random Numbers again : WAS RE: genetic inheritence in a primitive #2
In response to my warning about the use of SEED=0 with CALL RANUNI, Dan Nordlund <djnordlund@VERIZON.NET> wrote in part: > Art's use is not quite as problematic in that there is probably > more time between executions of the RANUNI subroutine in his > program. To test that hypothesis I duplicated Zach's data 10,000 times. I then ran Art's code changing the DATA statement to keep X. Here is the resulting freq. Cumulative Cumulative x Frequency Percent Frequency Percent ��������...

Fully definable ports of array of std_logic_vectors?
Hello, I have a construct that I would like to build to have fully definable ports which are arrays of std_logic_vectors, but from what I have read, I haven't figured out yet a way to do this in VHDL-1987/1993/2002. It seems that this will be possible in VHDL-200X. Does anybody know a way that I could create a functional equivalent to this using one of today's standards? I don't think that using a package to define the types is really an option since I will be instantiating multiple copies of this in the same design with different array and vector lengths (correct me if I'm...

Pointer arithmetics in 2D arrays
Is this code legal (according to the strictest possible sane[1] interpretation of the standard, regardless of wheter it does work on all implementations in the known universe)? #include <stdio.h> void print_square_matrix(int *ptr, int order) { int i, j; for (i = 0; i < order; i++) { for (j = 0; j < order; j++) printf("%3d ", *ptr++); putchar('\n'); } } int main(void) { int matrix[3][3] = { {157, 64, 13}, { 0, -16, 128}, { 54, 42, -23} } int *p = &matrix[0][0...

array of reference?
why can't we have array of references. siddhu wrote: > why can't we have array of references. References are not objects. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask * siddhu: > why can't we have array of references. A reference is not an object, it has no size. -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? On Dec 5, 2:25 am, siddhu <siddharth....@...