#### join two binary numbers

I want to join two binary numbers like
$a=1101$b=1001
and i want the result to be 11011001
join is not working for me.
Can anybody suggest something


 0
5/22/2006 11:31:32 AM
comp.lang.perl.misc 33123 articles. 1 followers. brian (1246) is leader.

11 Replies
230 Views

Similar Articles

[PageSpeed] 46
hara wrote:
> I want to join two binary numbers like
> $a=1101 >$b=1001
> and i want the result to be 11011001
> join is not working for me.
> Can anybody suggest something
>

Do you want them to be treated as numbers or strings? Please post a
complete example Perl script (the lines above would not compile).

DS

 0
David
5/22/2006 11:37:01 AM
hara wrote:
> I want to join two binary numbers like
> $a=1101 >$b=1001
> and i want the result to be 11011001
> join is not working for me.
> Can anybody suggest something
>
$c =$a . $b; -- Tony Green Ipswich, Suffolk, UK, http://www.beermad.org.uk * This has been a Microsoft-free message *   0 Tony 5/22/2006 11:37:41 AM Hi hara > I want to join two binary numbers like >$a=1101
> $b=1001 > and i want the result to be 11011001 > join is not working for me. as David already pointed out, your example does not provide information on what you *really* want. > Can anybody suggest something$a = '1101';
$b = '1001';$c = $a .$b;
print $c; Regards, Mirco   0 Mirco 5/22/2006 11:40:58 AM hara wrote: > I want to join two binary numbers like >$a=1101
> $b=1001 > and i want the result to be 11011001 > join is not working for me. > Can anybody suggest something$ perl -e'
my $x = 0b1101; my$y = 0b1001;
printf "%b\n", $x << 4 |$y;
'
11011001

John
--
use Perl;
program
fulfillment

 0
John
5/22/2006 12:02:54 PM
hara <hara.acharya@gmail.com> wrote:
> I want to join two binary numbers like
> $a=1101 >$b=1001

Those are in decimal, not in binary.

"join" is not an operation that is defined for numbers.

> and i want the result to be 11011001

You do not have 2 binary numbers then, you have 2 strings.

The operation defined for "joining" strings is named "concatenation".

> join is not working for me.

> Can anybody suggest something

Show the code you have so far.

--
Fort Worth, Texas

 0
5/22/2006 12:54:18 PM
>>>>> "TG" == Tony Green <news@beermad.REMOVE.TO.REPLY.org.uk> writes:

TG> hara wrote:
>> I want to join two binary numbers like
>> $a=1101 >>$b=1001
>> and i want the result to be 11011001
>> join is not working for me.
>> Can anybody suggest something
>>
TG> $c =$a . $b; if join didn't do the trick, why would . be any better? join is just a loop over . and this is beside the point that the OP's question is massively vague as we have no clue as to the format of the data and desired results. uri -- Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org   0 Uri 5/22/2006 10:32:08 PM "hara" <hara.acharya@gmail.com> wrote: > I want to join two binary numbers like >$a=1101
> $b=1001 Notice that a and b are not binary numbers, but 1,101 and 1,001. > and i want the result to be 11011001 > join is not working for me. try: printf "%04d%04d",$a, $b; Since you didn't give a clear example of "not working" I had to guess, and my guess is that your leading zeroes are eaten away:$a = 0010;
$b = 1001; Another option is to quote your numbers, so they are strings, since you are glueing them together as strings. E.g.$a = '0010';
$b = '1001'; print "$a$b"; Final note: don't use$a and $b, it might bite you one day. -- John Bokma Freelance software developer & Experienced Perl programmer: http://castleamber.com/   0 John 5/22/2006 11:27:13 PM hara schreef: > I want to join two binary numbers like >$a = 1101
>   $b = 1001 > and i want the result to be 11011001 > join is not working for me. > Can anybody suggest something my$x = '1101' ;
my $y = '1001' ; printf "%08b\n", oct("0b$x") << 4 | oct("0b$y") ; -- Affijn, Ruud "Gewoon is een tijger."   0 Dr 5/23/2006 6:43:56 AM My idea is to make a binary number into a 6 digit number. >From a calculation i may get a 2/3/4 digit number and i want to convert it to 6 digit number by adding zeros on the left of that number. Suppose i got$a="1101";
To make it 6 digit i tried doing it like
$res="000000" |$a;
But i am getting
110100
But i want
001101
Is it possible to do that?


 0
hara
5/23/2006 8:04:13 AM
Hi hara
> Suppose i got
> $a="1101"; > To make it 6 digit i tried doing it like >$res="000000" | $a; > But i am getting > 110100 > But i want > 001101 > Is it possible to do that? You can do all these things with printf/sprintf:$number = 33; # decimal
...
printf "%06b", $number; ... or you can use some ideas from the Perl-Cookbook (Ch. 2.4) ...$n  = bin2dec('0110110');
printf "%06b", $n; ... sub bin2dec { return unpack("N", pack("B32", substr("0" x 32 . shift, -32))); } ... But you should'n be confused about the 'internal' representation of numbers. Regards Mirco   0 Mirco 5/23/2006 8:36:09 AM hara wrote: > My idea is to make a binary number into a 6 digit number. >>From a calculation i may get a 2/3/4 digit number and i want to convert > it to 6 digit number by adding zeros on the left of that number. Finally you tell us what you really want: it is an output formatting problem. Nothing to do with or'ing binary numbers. Do you really imagine that Perl is somehow storing binary numbers of sub-byte size? You are still ignoring the posting guidelines for this group though. Many here will be running out of patience. Quote context. Post complete scripts. > Suppose i got >$a="1101";
> To make it 6 digit i tried doing it like
> $res="000000" |$a;
> But i am getting
> 110100

As you have been told many times already, that is because "1101" is a
*string* of four characters, and "000000" is a *string* of six
characters. They are not binary numbers.

Let's consider your example. Complete script:

----

#!/usr/bin/perl
use strict;
use warnings;

my $num = '1101'; my$res = '000000' | $num; print$res;

----

Output: 110100

What is happening here? Perl is doing an bitwise or of each *byte* of
the two strings, padding $num of the right with two zero bytes to match the length of$res.

Perhaps this will convince you. The ASCII code for '3' is 0b00110011.
For '4' it is 0b00110100. For '7' it is 0b00110111. So, a bitwise or of
'3' and '4' will give '7'. Let's see:

----

#!/usr/bin/perl
use strict;
use warnings;

my $num = '1103'; my$res = '000400' | $num; print$res;

----

Output: 110700

Likewise '1103' | '000a00' results in '110s00', since the ASCII codes
are '3': 0b00110011, 'a': 0b01100001, 's': 0b01110011.

> But i want
> 001101
> Is it possible to do that?

See the many solutions already posted here.

DS

 0
David
5/23/2006 10:42:58 AM
Similar artilces about - join two binary numbers:

partial key join in sql
I'm asking for opinions advice and guidance for making a partial key join. All comments welcome. I need to select a few rows from a large table. The old code performas a 30 minute data step merge data selected; merge wanted( in= wanted ) big( in= big keep= <various variables> where=( <subset stuff> ) ) ; by A ; if wanted ; run; Table "big" is indexed, say like index=( key=( a b c)/unique ) Set statement with KEY= is hampered by the absence of B and C from the rows in table "wanted" SQL defa...

augmented binary tree data structure
A data structure can be "augmented" by defining new information for it to maintain. One commonly useful way to augment a binary search tree-based data structure is to define part of its data as a function of its immediate children's data. Furthermore, augmented data defined in this way can be efficiently maintained as the tree changes over time. For example, suppose we define the "size" of a node as the sum of the "size" of its immediate children, plus 1. In such an annotated BST with height H, we can find the node that would be Kth in in-order traversal i...

Directory numbers
Hey, I'm getting this error: EXT3-fs error (device md1): ext3_readdir: bad entry in directory #29508430: rec_len % 4 != 0 - offset=0, inode=1752463696, rec_len=28271, name_len=45 How can I find out which directory is #29508430 ? I tried googling it but to no avail, maybe I'm using the wrong terms. Thanks in advance! -- Sune Beck On 3 Jan 2007 02:21:47 -0800, sunebeck@gmail.com staggered into the Black Sun and said: > EXT3-fs error (device md1): ext3_readdir: bad entry in directory > #29508430: rec_len % 4 != 0 - offset=0, inode=1752463696, > rec_len=28271, name_len=45...

[News] Two New Reviews of the Gentoo-based Zonbu Linux Laptop
Zonbu Zonbook Review ,----[ Quote ] | While the Zonbu approach will not satisfy anyone who likes to tinker with his | or her PC or needs unfettered access to the widest possible range of software | and peripherals, anyone looking for a reasonably priced, competent, and | low-hassle laptop should give the Zonbook a look. `---- http://itmanagement.earthweb.com/osrc/article.php/3735926 Review: Zonbu Laptop ,----[ Quote ] | You want a computer but you are not into gaming. You want a simple yet | somewhat powerful computer without breaking your energy bill. You also want a | simple an...

Call For Papers
CALL FOR PAPERS -- AMAS-BT 2009 2nd Workshop on Architectural and Microarchitectural Support for Binary Translation Held in conjunction with the 36th Int'l Symposium on Computer Architecture (ISCA-36) Austin, Texas -- June 20, 2009 http://amas-bt.cs.virginia.edu/ Workshop Overview Long employed by industry, large scale use of binary translation and on-the-fly code generation is becoming pervasive both as an enabler for virtualization, processor migration and also as processor implementation technology. The emergence and expected growth of just- in-time compilation, virtualization and ...

FileMaker Pro 7
I am new to FileMaker, and I cannot figure out how I might do the following: I am trying to create a database which keeps track of RMA's. The RMA# needs to be structured using the date as follows: YYMMDD## where ## is the 2-digit number telling how many RMA's have been issued for that date. An example might be as follows: The 3rd RMA issued on November 15th, 2004 would appear as: 04111503. This RMA number is going to be the primary key for my RMA records table as it will uniquely identify every RMA ever issued. Can anybody tell me the best way to auto-generate this number each...

Counting the number of inputted files in a document, help...
Hi comp.tex, My goal is to count the number of input files between the 'begin' and 'end' appendices environment like so... \begin{appendices) \input{file A} \input{file B} \end{appendices} I want to keep track of how many files are inputted in a variable called \filecount for example. How do I do that? Thanks for any feedback. Alvin Das Alvin Das wrote: > My goal is to count the number of input files between the 'begin' and > 'end' appendices environment like so... > > \begin{appendices) > \input{file A} > \input{file B} > \end{appendic...

Two CLOS questions
1. How does one create a method object of the sort that one would pass as the second argument to a non-vacuous call to add-method? (I put the non-vacuous qualifier in there because the obvious answer to the question is to use defmethod, but if you use defmethod then the method is already added and there is no need to call add-method.) 2. Can someone please point me to an example of how one might use a non-standard method qualifier or (even better) multiple method qualifiers in a single method? Thanks, rg Ron Garret wrote: > 1. How does one create a method object of the sort tha...

sending a mail with a file joined
Hi! I would like to know how to send, if possible, a mail with a file joined ? I want the to be joined, not included in the body of the mail. Thanks for your help. On Mon, 28 Jun 2004 21:09:23 +0200, Rahan , le fils des �ges farouches <nospam@rahan.com> wrote: > > > Hi! > I would like to know how to send, if possible, a mail with a file joined ? > I want the to be joined, not included in the body of the mail. > Thanks for your help. You must mean "attached" instead of "joined". Your mail client should handle that. If you are using mail(x), you ...

Re: i am having a problem with while loops, i have two while loops, i have a random number generator inside the &quot;inside&quot; loop and i want to read an array outside the &quot;outer&quot;
I think I have a similar problem - I have a while loop with Flat Sequence controlled for loop that produces output. This output needs to be displayed every while loop pass, but I get no output as the while loop feeds back thru a shift register and repeats all the innner funcions without sending the ouput to form new entries in the array. &nbsp; Is there any way we could stop the while loop for a split second (but practically just for no time, so that no time is wasted when it outputs the data)? &nbsp; Or is it a bad approach altogether? &nbsp; Appreciate any advice. &nbsp; kolo...

Divide Two variable in different data sets
Hi All, I have to divide the variable values in two different SAS data set. How do I do that? Thanks. You may use 'if ... then output' to partition the data with its values. Here is an example. HTH 977 data t1; 978 do val='a','b'; 979 output; 980 end; 981 run; NOTE: The data set WORK.T1 has 2 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 982 983 data ta tb; 984 set t1; 985 if val='a' then output ta; 986 else out...

Table Join Question
Hi All, New to access and I have a question. I have a master table with a 6 character field which I join to another product table with a similar 6 character field. Tables have thousands of records. Recently the master table has started to use 9 characters instead of 6 but only for a small number of records. I can change the product table to 9 characters but how would I join the 2 tables given the master only has 9 character for a small number of records. Have no experience of SQL so am I way out of my depth. mattie On Thu, 28 May 2009 04:31:43 -0700 (PDT), mattie <mchugh.p.a@gmail.com...

threads: to join or not to join
I have just discovered that when a java program starts one of more threads and then the main thread comes to the end of function main, the program will wait for the other threads to complete unless the threads are daemon threads. This comes as quite a suprise to me. Does this mean there is an implicit join? Regards, Andrew Marlow On Wed, 27 Aug 2008 00:04:45 -0700, marlow.andrew wrote: > Does this mean there is an implicit join? Sort of. If I look at the Sun JVM it's not an implcit join in your main method, but it looks like at end of main DestroyVM is called which itself waits f...

two questions #2 799264
hello everyone, I have two questions: 1) I ahe a axe x,y. How to obtain x-axis values ? I would like create a loop which recuperate this values. 2)I have plot 2 curves in 2 axes (x-axis is the time: from 0 to 500 seconds). I have create a zoom menu. I would like to zoom on the 2 x-axis at the same time. How can i do please? Thanks ...

Comparing two tables for differences
In a convoluted way, I started a topic about trying to find the differences between two tables. I wanted to know the old and new values for the particular fields that were changed from one version of the table to another. Just wanted to pass along the news that it can be done. Another DBA pointed me to the following link, which turned out to be exactly what I needed... http://www.oracle.com/technology/oramag/code/tips2004/012504.html. Thanks to Sanjay Ray for developing this script and Oracle for sharing it. Saved me a lot of headaches. Just as an example of my problem... I want...

Guidance in determining phase difference between two sinusoidal signals needed
Hi, I need some guidance in the selection of an algorithm to solve a specific problem. My problem consists of determining the phase difference between two 150Hz (range within 1 Hz) sinusoidal signal with correlated noise between signals but with good signal-to-noise ratio. The estimation must be very precise (within 1x10(-7) rad if possible) and use a limited number of samples to keep latency low - an online algorithm could be the way to go as phase shifts happens slowly. I have been looking at high resolution sub space methods but I'm not sure this is the answer to my problem. My overvie...

check if object is number
Is there a good way to determine if an object is a numeric type? Generally, I avoid type-checks in favor of try/except blocks, but I'm not sure what to do in this case: def f(i): ... if x < i: ... The problem is, no error will be thrown if 'i' is, say, a string: py> 1 < 'a' True py> 10000000000 < 'a' True But for my code, passing a string is bad, so I'd like to provide an appropriate error. I thought about calling int() on the value, but this will also allow some strings (e.g. '1'). I guess thi...

OUTER JOIN problem
Hello I have to tables ar and arb, ar holds articles and a swedish description, arb holds descriptions in other languages. I want to retreive all articles that match a criteria from ar and also display their corresponding entries in arb, but if there is NO entry in arb I still want it to show up as NULL or something, so that I can get the attention that there IS no language associated with that article. I tried to use the following but it does not work correctly create procedure q_spr_languagecheckpervg @varugruppkod varchar(20), @sprakkod int AS select ar.artnr, ar.artbeskr, arb...

Join the M Revolution
Seen on Hacker News: http://opensource.com/health/12/2/join-m-revolution ...

round numbers
Hello, If the function is for instance: function x = y (p) x = p * 0.5; end How can I make this function automatically give round answers for x? (floor) On Feb 23, 11:41=A0am, "Lauren Philips" <lau...@trash2009.com> wrote: > How can I make this function automatically give round answers for x? (flo= or) Not wanting to *just* give you the answer. But try "help round" and look under "See Also". There's lots to learn in the help. "Lauren Philips" <lauren@trash2009.com> wrote in message > How can I make this function automatical...

How to Gnerate a Random ID Number
I just wana make a random id number based on4 digits-for examples?? Thanks in Advance Ch.Yallin "chico_yallin@yahoo.com" <chico_yallin@yahoo.com> wrote in news:1181388231.643515.94630@k79g2000hse.googlegroups.com: > I just wana make a random id number based on4 digits-for > examples?? > > Thanks in Advance > > Ch.Yallin > > see the help files on the rnd() function. -- Bob Quintal PA is y I've altered my email address. -- Posted via a free Usenet account from http://www.teranews.com chico_yallin@yahoo.com (chico_yallin@yahoo.com) wr...

tricky GROUP BY / JOIN question
Hello, I'm sorry I couldn't think up a more precise subject line. I would like to know whether the following can be implemented in SQL: The example below joins 4 tables ITEM, BRAND, MODEL and CONDITION. In human understandable terms: a [secondhand] Item is of a particular Model and Brand. The Items retail at different prices depending on their Condition. Required result set: Brand | Model | Cond | Cond | Price | Price | | min | max | min | max ------------------------------------------- Canon | A1 | Exc | Mint | 139 | 155 Canon | F1N | Exc+...

Declaring a two-dimesional array in javascript
Hi to all, I have this problem in declaring a two-dimesional array, how will i declare such array with unknown number of rows? Your help will be very much appreciated. Thanks in advance. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! ms_chika said: > >Hi to all, >I have this problem in declaring a two-dimesional >array, how will i declare such array with unknown number of rows? > >Your help will be very much appreciated. Thanks in advance. Javascript doesn't support two-dimensional arrays, bu...

[OT] JOIN in MySQL
Although my query kind of works, I'd appreciate some ideas to improve it. I have the following database running under MySQL 3.23.58: ::: users :::::::::::::::::: user_id age address active ------- --- --------- ------ 1 11 Foo St. 1 2 22 Foo Ave. 1 3 33 Foo Blvd. 1 4 44 Foo Road 1 5 55 Foo Alley 0 ::: pictures :::::::::::::: picture_id user_id file ---------- ------- -------- 1 1 foo1.jpg 2 1 foo2.jpg 3 1 foo3.jpg 4 3 foo4.jpg 5 4 foo5.jpg ...