Binary to Hex 
Author Message
 Binary to Hex

Hello

TP 6.0

How can i convert a Binary string to Hex?

Ex:
           10100101 to A5

Regards
                   Mikael



Sat, 13 Aug 2005 18:30:29 GMT  
 Binary to Hex

Quote:

> How can i convert a Binary string to Hex?

 165966 Jan 8 2000 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
 tsfaqp.zip Common Turbo Pascal Questions and Timo's answers, linked

   All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa

Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html



Sat, 13 Aug 2005 19:14:08 GMT  
 Binary to Hex



Quote:
> Hello

> TP 6.0

> How can i convert a Binary string to Hex?

> Ex:
>            10100101 to A5

> Regards
>                    Mikael

Split the number into groups of four bits.
Replace each group according to the following table

0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = a
1011 = b
1100 = c
1101 = d
1110 = e
1111 = f

b.t.w. is this homework?

--
Femme



Sat, 13 Aug 2005 20:13:40 GMT  
 Binary to Hex
Hello

No, not as in School Homework.
- but im doing it at home.

I need a routine to write to the Parallel port, and are using "port[]" to do
so.
and this must be in hex.

Regards
                 Mikael


Quote:



> > Hello

> > TP 6.0

> > How can i convert a Binary string to Hex?

> > Ex:
> >            10100101 to A5

> > Regards
> >                    Mikael

> Split the number into groups of four bits.
> Replace each group according to the following table

> 0000 = 0
> 0001 = 1
> 0010 = 2
> 0011 = 3
> 0100 = 4
> 0101 = 5
> 0110 = 6
> 0111 = 7
> 1000 = 8
> 1001 = 9
> 1010 = a
> 1011 = b
> 1100 = c
> 1101 = d
> 1110 = e
> 1111 = f

> b.t.w. is this homework?

> --
> Femme



Sat, 13 Aug 2005 20:17:42 GMT  
 Binary to Hex
Hello

I can not find anything in the faq that convert from Bin to Hex
I tried the HEXFN, HEX and BASE non of them came up with the right result:
Like this: 10100101 should be convertet to A5

Regards
                 Mikael


Quote:

> > How can i convert a Binary string to Hex?

>  165966 Jan 8 2000 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
>  tsfaqp.zip Common Turbo Pascal Questions and Timo's answers, linked

>    All the best, Timo

> --
> Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
> Department of Accounting and Business Finance  ; University of Vaasa

> Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html



Sat, 13 Aug 2005 20:27:02 GMT  
 Binary to Hex
Get the SWAG archives, it has much more stuff you might love to have...

it is here: www.gdsoft.com
Don't forget to download the reader.exe

Greetings

Markus



Sat, 13 Aug 2005 21:19:43 GMT  
 Binary to Hex

Quote:


> >  165966 Jan 8 2000 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
> >  tsfaqp.zip Common Turbo Pascal Questions and Timo's answers, linked
> I can not find anything in the faq that convert from Bin to Hex
> I tried the HEXFN, HEX and BASE non of them came up with the right result:
> Like this: 10100101 should be convertet to A5

Take a closer look at item 42.

HEXFN(BINDECFN('10100101')) gives 00A5.

Furthermore, it says
 For a full set of conversions, both from and to decimal, apply
 TSUTNTB.TPU from ftp://garbo.uwasa.fi/pc/ts/tspa357c.zip.

   All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa

Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html



Sun, 14 Aug 2005 05:37:44 GMT  
 Binary to Hex
hi mikael,


meinte Mikael Mortensen:

Quote:
> No, not as in School Homework.
> - but im doing it at home.
> I need a routine to write to the Parallel port, and are using
> "port[]" to do so.
> and this must be in hex.

are you sure?

what do you mean by hex? hex-string oder integer?

port[xy] := 'af9d' (a hex-string) will fail.

i think what you are looking for is something like a bin2int-function.
eg. like this untested one:

function bin2long(s: string): longint;
var
  i : integer;
  l : longint;
begin
  {make sure that s only consists of '0' and '1' }
  l := 0;
  for i:=1 to length(s)
  begin
    l := l shl 1;
    if s[i]='1' then inc(l)
  end;
  bin2long := l
end;

hth
jochen



Sun, 14 Aug 2005 17:20:00 GMT  
 Binary to Hex



Quote:
> Hello

> No, not as in School Homework.
> - but im doing it at home.

> I need a routine to write to the Parallel port, and are using "port[]"
to do
> so.
> and this must be in hex.

> Regards
>                  Mikael

Never heard of a printer accepting hexadecimal chars.

Years ago I had this problem writing graphic information in pixels to
the screen. If a grapic image accidently contained the bit following
order which constructs to the byte #26, the printer would loose its
count of passed bytes. It turned out that this corresponded to the eof
marker, which is never sent by "write(lpt,mybyte)". The solution was

  Procedure sendbyte(B : byte);     {send one byte to printer}
  const Lptportnum = 1;
  var Regs :registers ;
  begin
    Regs.ah := 0;
    Regs.al := B;
    regs.dx := Pred(Lptportnum);
    intr($17,regs);
  end;

hth.

--
Femme



Sun, 14 Aug 2005 19:30:22 GMT  
 Binary to Hex
[snip]

Quote:

> Never heard of a printer accepting hexadecimal chars.

Never heared that too, but I know printers which have a Hex-dump
facility. Might be handy for debugging printer programming things...

Greetings

Markus



Sun, 14 Aug 2005 22:06:23 GMT  
 Binary to Hex
Hello

It's not to a Printer but a Relay Board.

It Works if i write:

  port[$378] := $A5;

I came up with a solution That seems to do the trick.

Regards
                  Mikael


Quote:



> > Hello

> > No, not as in School Homework.
> > - but im doing it at home.

> > I need a routine to write to the Parallel port, and are using "port[]"
> to do
> > so.
> > and this must be in hex.

> > Regards
> >                  Mikael

> Never heard of a printer accepting hexadecimal chars.

> Years ago I had this problem writing graphic information in pixels to
> the screen. If a grapic image accidently contained the bit following
> order which constructs to the byte #26, the printer would loose its
> count of passed bytes. It turned out that this corresponded to the eof
> marker, which is never sent by "write(lpt,mybyte)". The solution was

>   Procedure sendbyte(B : byte);     {send one byte to printer}
>   const Lptportnum = 1;
>   var Regs :registers ;
>   begin
>     Regs.ah := 0;
>     Regs.al := B;
>     regs.dx := Pred(Lptportnum);
>     intr($17,regs);
>   end;

> hth.

> --
> Femme



Sun, 14 Aug 2005 23:33:32 GMT  
 Binary to Hex
Hello

Ups! Yes your right. Sorry.

I already made my own code. Not as nice as yours but it works.

Regards
                 Mikael


Quote:


> > >  165966 Jan 8 2000 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
> > >  tsfaqp.zip Common Turbo Pascal Questions and Timo's answers, linked

> > I can not find anything in the faq that convert from Bin to Hex
> > I tried the HEXFN, HEX and BASE non of them came up with the right
result:
> > Like this: 10100101 should be convertet to A5

> Take a closer look at item 42.

> HEXFN(BINDECFN('10100101')) gives 00A5.

> Furthermore, it says
>  For a full set of conversions, both from and to decimal, apply
>  TSUTNTB.TPU from ftp://garbo.uwasa.fi/pc/ts/tspa357c.zip.

>    All the best, Timo

> --
> Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
> Department of Accounting and Business Finance  ; University of Vaasa

> Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html



Sun, 14 Aug 2005 23:35:14 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. FAST binary to hex string conversion

2. Binary to Hex? Hex to Binary? -HELP!!

3. Convert hex to binary

4. Saving Binary Data to a Paradox Binary Field via Code

5. Converting binary (text file) to compress binary file

6. Hex to ASCII ??

7. octal to hex converison

8. Convert a String to HEX

9. an absolute beginner : HEX question

10. source - hex thingy

11. Hex to ASCII conversion ?

12. Hex in Delphi

 

 
Powered by phpBB® Forum Software