Using DAC in Arduino Due

I have some digital data which is in 8bit Binary number format(00000000) which I want to convert in to analog data using arduino Due. I have to convert digital data to analog values. I guess the DAC pins in Due will be helpful for that purpose. I need help regarding the code to convert the binary value through DAC and take the output.

the following code is to receive 8 bit binary digital data, which I want to convert to analog and send through DAC.Please help.

int A;

int Bin[]={0,0,0,0,0,0,0,0};

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);

pinMode (DAC1,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>0){
A=Serial.parseInt();
Serial.println(A);
DectoBin(A,Bin);
for(int i=0;i<=7;i++){
Serial.print(Bin*);*

  • }*

  • analogWriteResolution(8);*

  • Serial.println("\n New Conversion \n");*

  • }*
    void DectoBin(int Dec, int Bin[]){

  • for (int i=7;i>=0;i--){*

  • if (pow(2,i)<=Dec){*

  • Dec=Dec-pow(2,i);*

  • Bin[8-(i+1)]=1;*

  • }else{*

  • Bin[8-(i+1)]=0;*

  • }*

  • }*
    Please help

Integers are stored in binary in all computers and microcontrollers already, you probably don't need to do any conversion at all:

  analogWrite (DACpin, Serial.parseInt ()) ;

Thank you