All About Circuits Forum How to concatenate binary in C
 Register Blogs FAQ Members List Today's Posts Search Today's Posts Mark Forums Read

 Programmer's Corner Discussion forum for all aspects of programming and software engineering. Any software programming language welcome: C, C++, C#, Fortran, Java, Matlab, etc.

#1
05-15-2007, 02:55 PM
 Dave_ Junior Member Join Date: Mar 2007 Posts: 28
How to concatenate binary in C

Hi all

My wish is to concatenate two binary numbers into one variable size vector, such as below:

A = 1111
B = 0000

C = A & B

C now equals 11110000

I found some solutions for C++, but none for C. Is it even possible?

Thanks

Dave
#2
05-15-2007, 03:10 PM
 recca02 Senior Member Join Date: Apr 2007 Location: India-22.35° N 82.68° E. Posts: 1,211

well i dont know much abt c,
is concatenating strings different than concatenating binary numbers,
otherwise i think even a noob like me can do it myself.
#3
05-15-2007, 07:01 PM
 Dave_ Junior Member Join Date: Mar 2007 Posts: 28

I was hoping there was a simple command to do it like '&' as used in VHDL. Perhaps I will have to do it the string way.
#4
05-15-2007, 10:44 PM
 Papabravo Senior Member Join Date: Feb 2006 Location: Michigan, USA (GMT-5) Posts: 5,849

If you know the length of the strings you can combine them with shifting and boolean operations.
Code:
`C = (A<<4) | B ;`
Select All
With strings you need to use library functions. There are no string concatenation operators in C. Literal strings can be concatenated explicitly as initializers or printf arguments.
__________________
We never have time to do it right,
But we always have time to do it over.
#5
05-15-2007, 11:03 PM
 Dave_ Junior Member Join Date: Mar 2007 Posts: 28

Oh damn. Ok, cheers for that Papabravo.

 Tags binary, concatenate

 Related Site Pages Section Title Worksheet Boolean algebra Worksheet Binary math Worksheet Numeration systems Textbook Look-up tables : Principles Of Digital Computing Video Lecture Boolean Algebra - Postulates - Digital Video Lecture Digital Concepts & Terms - Digital Textbook Binary count sequence : Sequential Circuits Counters Textbook A Full-Adder : Combinational Logic Functions Textbook 7-segment display : Digital Integrated Circuits Textbook Octal and hexadecimal numeration : Numeration Systems

 Similar Threads Thread Thread Starter Forum Replies Last Post MrSoftware Embedded Systems and Microcontrollers 4 10-30-2013 09:16 PM Mussawar Electronics Resources 7 04-07-2013 02:03 PM PG1995 Math 13 10-18-2011 01:57 PM count_volta Math 5 03-19-2011 12:47 AM count_volta Programmer's Corner 17 12-18-2010 05:36 PM

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Electronics Forums     General Electronics Chat     The Projects Forum     Homework Help     Electronics Resources Software, Microcomputing, and Communications Forums     Programmer's Corner     Embedded Systems and Microcontrollers     Computing and Networks     Radio and Communications Circuits and Projects     The Completed Projects Collection Abstract Forums     Math     Physics     General Science All About Circuits Commmunity Forums     Off-Topic     The Flea Market     Feedback and Suggestions

All times are GMT. The time now is 01:23 PM.